JPA: Unique Collection "OneToMany"
I want to display a "collection". A collection is a group of items that the user can group as desired.
@Entity
class Item {
Long id;
String name
}
@Entity
class MyCollection {
Long id;
String name;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
Set<Item> items;
}
The user must be able to put the Item
name "foo" in the "MyCollection" the name "bar" and in the "MyCollection" the name "bar2"
The junction table JPA / Hibernate generated for me MyCollection_Item
has 4 indexes, PK ( MyCollection_id, Item_id
), unique index ( Item_id
) and 2 foreign keys.
I don't want it to create a unique index on Item_id
. This is preventing me:
MyCollection_id, Item_id
1, 1
1, 2
2, 1
I'm sure this type of display should be possible? Any help would be greatly appreciated.
source to share