>>>>> [Test Fork|https://github.com/TheJhonny007/hibernate-test-case-templates] <<<<<
In order to make my Collections observable for JavaFX I used the JavaFX bean convention to wrap them in javafx.beans.Properties.
Hibernate is not able to refresh Entities with Collections ({{ElementCollection}}, {{ManyToMany}}, {{OneToMany}}) correctly.
{code:Java} @Entity public class Person {
private int id;
@Id @GeneratedValue(strategy = GenerationType.AUTO) public int getId() { return id; } public void setId(int id) { this.id = id; }
private final ListProperty<String> contacts = new SimpleListProperty<>(FXCollections.observableArrayList()); public final ListProperty<String> contactsProperty() { return contacts; }
@ElementCollection public List<String> getContacts() { return contacts.get(); } public void setContacts(List<String> contacts) { this.contacts.set(FXCollections.observableList(contacts)); } } {code}
In this Example the {{contacts}} are wrapped inside a {{ListProperty}}, so the ui gets notified on changes. I provide JPA with property acces on the {{getContacts()}} method.
All operations seem to work fine with the property access. It is possible to
- {{persist()}} a {{Person}} ({{contacts}} in the DB Table are being inserted) - {{find()}} a {{Person}} (the {{contacts}} are fetched correctly from the DB and are available in {{contactsProperty()}} and {{getContacts()}}) - {{flush()}} a change to a {{Person}} ({{contacts}} are being updated in the DB Table correctly)
But it is not possible to {{refresh()}} a {{Person}}. The {{contacts}} do not get updated. |
|