1

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.

}
dkaisers
  • 824
  • 1
  • 8
  • 15
  • What version of eclipselink are you using and post a bit of the stack trace showing the loop - the exception stack if its recursive and results in an error, or obtain a thread dump otherwise – Chris Jan 31 '14 at 06:19
  • probably a question not so relevant to the problem you are facing. But, why wouldnt you rather use the `Person` and `Job` relation in your `staff` entity? By using it as `@Embeddable` are you asserting that you wouldnt want to query the `Job` and `Person` without having to reference to `Staff` ? Also, the reason i ask is because of the loss of `Cascade` in case of using the @Embeddable – Hrishikesh Jan 31 '14 at 08:49
  • @Chris It's version 2.5. I can't give you a stacktrace, because - as I mentioned in the original post - there is none. The method does not throw anything, it simply never stops running. The longest I've waited were about 30 minutes while I was eating dinner... – dkaisers Jan 31 '14 at 11:15
  • @Hrishikesh The combinaiton of a Person and a Job is only relevant to the Staff object it belongs to. The three entities exist for themselves. When a Staff object is persisted, deleted, etc. the underlying Person and Job already exist and are not to be altered. I hope that helps your understanding. – dkaisers Jan 31 '14 at 11:18
  • If it isn't resulting in a stack overflow, then you need to get a thread dump to see what is going on and what it's doing. Getting a thread dump is described a few places but depends on your environment. See http://stackoverflow.com/questions/2124672/java-stack-dump-on-windows and http://helpx.adobe.com/experience-manager/kb/TakeThreadDump.html You might turn on eclipselink logging to finest to see what it is doing as well. – Chris Jan 31 '14 at 12:48

0 Answers0