一尘不染

注释ConcurrentHashMap时,在休眠中“非法尝试将非集合映射为@ OneToMany,@ ManyToMany或@CollectionOfElements”

hibernate

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

@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)

阅读 264

收藏
2020-06-20

共1个答案

一尘不染

查看主题6.1。在此链接上的永久性收藏。

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

2020-06-20