"Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements" in hibernate when annotating a ConcurrentHashMap
hibernate, java
Solution
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.)
Problem
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) ```