Forums Register Login

JavaFX + JPA and SimpleSetProperty

+Pie Number of slices to send: Send
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
1
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
> 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).
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4536 times.
Similar Threads
Metamodel - Attribute.isAssociation()
problem with one to many relationship
Wildfly EAR application deploy on startup problem
How to update table of one fxml by clicking button of other fxml?
JavaFX 2: Get TableCell Row Index
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:59:12.