“非法尝试将非收藏映射为@OneToMany,@ManyToMany或@ CollectionOfElements”在注释一个ConcurrentHashMap时在休眠 [英] "Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements" in hibernate when annotating a ConcurrentHashMap
问题描述
我尝试了注解一个属性访问器,它的返回值是一个映射,如下所示:
@MapKeyColumn(name = parameter_name)
@ElementCollection
public ConcurrentHashMap< String,Serializable> getParameterValues()
这符合hibernate用户指南(第2.2.5.3.4节)。 。但是,我得到:
org.hibernate.AnnotationException:非法尝试将非集合映射为@OneToMany,@ManyToMany或@CollectionOfElements:ConfigurationParameterBag.parameterValues在org.hibernate.cfg.annotations.CollectionBinder.getCollectionBinder(CollectionBinder.java:324)
在org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1723)在org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
在org.hibernate.cfg.AnnotationBinder.bindClass
(AnnotationBinder.java:707)
在org.hibernate作为.cfg.Configuration $ MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
在org.hibernate.cfg.Configuration $ MetadataSourceQueue.processMetadata(Configuration.java:3989)
在org.hibernate.cfg.Configuration .secondPassCompile(Configuration.java:1398)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:1002)
at org.hibe rnate.tool.hbm2ddl.SchemaExport<初始化>(SchemaExport.java:130)在org.hibernate.tool.hbm2ddl.SchemaExport
将INIT>(SchemaExport.java:92)
查看主题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的实现。)
I've tried annotating a property accessor whose return value is a map as follows:
@MapKeyColumn(name="parameter_name")
@ElementCollection
public ConcurrentHashMap<String, Serializable> getParameterValues()
This is in accordance with the hibernate user guide (section 2.2.5.3.4.). However, I get:
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)
Check out the topic 6.1. Persistent collections on this link .
From the link,
Hibernate requires that persistent collection-valued fields be declared as an interface type. The actual interface might be java.util.Set, java.util.Collection, java.util.List, java.util.Map, java.util.SortedSet, java.util.SortedMap
or anything you like ("anything you like" means you will have to write an implementation of org.hibernate.usertype.UserCollectionType.)
这篇关于“非法尝试将非收藏映射为@OneToMany,@ManyToMany或@ CollectionOfElements”在注释一个ConcurrentHashMap时在休眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!