我想映射一个“集合”。集合是一组用户可以随意组合的项目。JPA:非独特的“OneToMany”系列
@Entity
class Item {
Long id;
String name
}
@Entity
class MyCollection {
Long id;
String name;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
Set<Item> items;
}
用户应该能够把Item
名称为“foo”到了`MyCollection的”名称‘栏’,并进入‘MyCollection的’名‘BAR2’
是JPA/Hibernate是为了创建连接表我,MyCollection_Item
已经有4个索引,PK(MyCollection_id, Item_id
),唯一索引(Item_id
)和2个外键。
我不想让它在Item_id
上创建唯一索引。这使我不必:
MyCollection_id, Item_Id
1, 1
1, 2
2, 1
我相信这种类型的映射必须是可能的吗?任何帮助将不胜感激。
尝试使用manyToMany – BobTheBuilder 2013-02-14 16:06:08