2

I have basically two Entities Entity1 and Entity2. Entity1 contains this bit of Code:

@OneToMany(cascade=CascadeType.PERSIST)
@OrderColumn
List<Entity2> e = new LinkedList<Entity2>();

and Entity2 contains some stuff, but nothing relevant. I want to add some instances to the list e, and most importantly i want to add some duplicates (the same reference) twice or more to the list. Still i want JPA to persist both and i want JPA to persist the Order of the list.

So far this works, if i add only unique items. If i add a duplicate, JPA actually wants to persist the correct data (ID od Entity1, ID of Entity2 and the order) but since the Primary key of the relationship table is only the two IDs, JPA throws an duplicate primary key error.

How can i solve this?

Simiil
  • 2,281
  • 1
  • 22
  • 32

1 Answers1

2

EclipseLink does not currently support duplicates for OneToMany relationships. Duplicate are support for (basic) ElementCollection mappings.

Please vote for bug, https://bugs.eclipse.org/bugs/show_bug.cgi?id=256978

The best solution is to map the join table to another entity and define a 1-m to it with a 1-1 to the target.

James
  • 17,965
  • 11
  • 91
  • 146