2011-11-17 24 views
15

我已經試過註釋屬性訪問,其返回值時是圖如下:「非法嘗試映射非集合作爲一個@OneToMany,@ManyToMany或@CollectionOfElements」休眠註釋即ConcurrentHashMap

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

這符合休眠用戶指南(第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) 

回答

41

檢查出話題6.1。持久收藏品link

從鏈接中, Hibernate要求將永久性的集合值字段聲明爲接口類型。實際的接口可能是java.util.Set, java.util.Collection, java.util.List, java.util.Map, java.util.SortedSet, java.util.SortedMap或任何你喜歡的東西(「你喜歡的任何東西」意味着你將不得不編寫org.hibernate.usertype.UserCollectionType的實現。)

+0

謝謝@kalatta它幫助了我:) – Ragul