• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaFX + JPA and SimpleSetProperty

 
andres gorze
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am currently developing and application using JAVAFX, JPA, EclipseLink...
So far so good, I could use a POJO that JPA and JAVAFX likes and works, until I needed to add a Set, the Set in the JavaFX world is a SetProperty, So I added it:

I have a pojo defined like this: (I simplified all code)



the other department class is like:




I am getting this error now:

Exception [EclipseLink-127] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The get method for the attribute [depts] does not return a ValueHolderInterface, but the mapping uses indirection.
Mapping: org.eclipse.persistence.mappings.OneToManyMapping[permisos]
Descriptor: RelationalDescriptor(package.Company --> [DatabaseTable(Company)])



What am I doing wrong?
Maybe JPA is not understanding ObservableSet? what should I use as a Set in JavaFX that is also compatible with JPA?

Many thanks
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have an answer to your specific question regarding ObservableSet. Just some info for consideration.

---

You may wish to consider using a MVVM style architecture:
https://en.wikipedia.org/wiki/Model_View_ViewModel

So, your model directly models your database entities and business logic and does not use JavaFX style properties.

The ViewModel contains JavaFX style properties.

Some info on how you might set this up: Put together JavaFX properties and JPA Entities (NO MIXED MODE)

Such a solution has some drawbacks as probably it won't be very dry and may require additional logic for data co-ordination.
But, on the other hand an MVVM solution would likely may avoid some issues that you may run across when some view properties are in entity model classes (such as the ObservableSet one). MVVM would also allow you to have a model which closely follows your domain and view-model classes which closely follow your UI.

---

If you wish to include JavaFX properties in JPA classes, then this example by james-d might be interesting. It also won't address your set question. The reasoning behind the code in James's example is explained in his blog.

Another, lightweight alternative is to use PropertyChangeSupport in the entity bean.
 
andres gorze
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,

I understand what you are saying, the thing is, I am pretty advanced in the development so I think I wont change the architecture at this point.
Is this the only way to do it? can I use another type of Collection that works natively?

Many many thanks for all your help.
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Is this the only way to do it? can I use another type of Collection that works natively?

Well you can always use standard java.util collections like List or Set, you don't need to use JavaFX Observable collections in your entity code. Hibernate/JPA works fine with java.util collections.

There are factory methods in FXCollections for creating ObservableLists from standard java.util collections when you need them. You won't get change notifications when the backing list changes with such a setup, but you might not need that and if you do, you can set up an alternate change notification mechanism (I don't have any code for that).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic