草庐IT

java - 注释 ConcurrentHashMap 时处于 hibernate 状态的 "Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements"

coder 2023-08-28 原文

我试过注释一个属性访问器,其返回值是一个映射,如下所示:

@MapKeyColumn(name="parameter_name")
@ElementCollection
public ConcurrentHashMap<String, Serializable> getParameterValues()

这符合 hibernate 用户指南(第 2.2.5.3.4 节)。但是,我得到:

org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: ConfigurationParameterBag.parameterValues
at org.hibernate.cfg.annotations.CollectionBinder.getCollectionBinder(CollectionBinder.java:324)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1723)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:1002)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:130)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:92)

最佳答案

查看主题 6.1。此 link 上的持久集合.

从链接, Hibernate 要求将持久的集合值字段声明为接口(interface)类型。实际接口(interface)可能是 java.util.Set、java.util.Collection、java.util.List、java.util.Map、java.util.SortedSet、java.util.SortedMap 或任何您喜欢(“任何你喜欢的”意味着你必须编写 org.hibernate.usertype.UserCollectionType 的实现。)

关于java - 注释 ConcurrentHashMap 时处于 hibernate 状态的 "Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8169196/

有关java - 注释 ConcurrentHashMap 时处于 hibernate 状态的 "Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements"的更多相关文章

随机推荐