我已按照this tutorial实施自定义集合。
我还注释了我的实体的相应属性:
@OneToMany(cascade = ALL, mappedBy = "plan", fetch = EAGER, orphanRemoval = true)
@CollectionType(type = "my.namespace.MyCustomCollectionType")
public MyCustomCollection getThings() {
return things;
}
然而,在创建映射时,Hibernate抱怨:
Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements
根据Hibernate documentation,这应该没问题。我应该能够在方法签名中使用我的自定义集合,因为我使用自定义集合类型注释:
实际的接口可能是java.util.Set,java.util.Collection,java.util.List,java.util.Map,java.util.SortedSet, java.util.SortedMap或任何你喜欢的东西(“你喜欢的任何东西”的意思是 你将不得不写一个实现 org.hibernate.usertype.UserCollectionType)。
我不知道出了什么问题。
答案 0 :(得分:1)
好的,我发现了我的问题。
首先,为了更清楚,是的,我有2个班级。 第一个是我的自定义集合( MyCustomCollection ),另一个是扩展UserTypeCollection( MyCustomCollectionType ),这是Hibernate为支持所需的技术接口自定义集合。
无论如何,我已经弄清楚出了什么问题:
我通过查看Hibernate中的测试套件来解决这个问题。 There are a couple of examples
但遗憾的是, PersistentSet 扩展了非泛型集合,因此,您也必须声明非泛型集合。
这是Jira bug for it。它已经存在了一段时间。