I am using EclipseLink for this. I have a ternary relation between three entities called Staff, Person and Job. I introduced the Embeddable class StaffItem that consists solely of a Person and Job. Staff has an ElementCollection of StaffItems.
I have no problem persisting new StaffItems to the Database, that were added to a Staff Entity, but whenever I change one item or delete it and try to merge the existing Staff Entity, the EntityManager seems to run into an infinite loop on the flushing. I do not get an error or exception, I simply do not return from the flush().
Staff.java
@Entity
public class Staff {
private List<StaffItem> staffItems;
@ElementCollection
@CollectionTable(name = "staff_items", joinedColumns = @JoinedColumn(name = "staff"))
public List<StaffItem> getStaffItems() { ... }
// setter, etc.
}
StaffItem.java
@Embeddable
public class StaffItem {
private Person person;
private Job job;
@ManyToOne
@JoinColumn(name = "person", referencedColumn = "id")
public Person getPerson() { ... }
@ManyToOne
@JoinColumn(name = "job", referencedColumn = "id")
public Job getJob() { ... }
// setter, etc.
}