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?