"Illegal attempt to map non-collection to @OneToMany, @ManyToMany or @CollectionOfElements" in hibernate when annotating ConcurrentHashMap


A:

I tried to annotate a property accessor whose return value is a map like this:

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

This complies 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)
Calata:

See topic 6.1. Persistent collection at this link .

From the link, Hibernate requires persistent collection-valued fields to be declared as interface types. The actual interface could be or java.util.Set, java.util.Collection, java.util.List, java.util.Map, java.util.SortedSet, java.util.SortedMapwhatever you like ("whatever you like" means you will have to write an implementation of org.hibernate.usertype.UserCollectionType.)

Related


Preserve constructor when annotating fields

Nason: I have the following class. public class StatusCategory { @JsonProperty("key") private final String m_key = null; public String getKey() { return(m_key); } } What -keepoptions are there to ensure that Proguard doesn't delete the c

Preserve constructor when annotating fields

Nason I have the following class. public class StatusCategory { @JsonProperty("key") private final String m_key = null; public String getKey() { return(m_key); } } What -keepoptions are there to ensure that Proguard doesn't delete the co

Preserve constructor when annotating fields

Nason I have the following class. public class StatusCategory { @JsonProperty("key") private final String m_key = null; public String getKey() { return(m_key); } } What -keepoptions are there to ensure that Proguard doesn't delete the co

Preserve constructor when annotating fields

Nason: I have the following class. public class StatusCategory { @JsonProperty("key") private final String m_key = null; public String getKey() { return(m_key); } } What -keepoptions are there to ensure that Proguard doesn't delete the c

Hibernate/JPA - Annotating bean methods vs fields

benstpierre: I have a simple question about Hibernate usage. I keep seeing people using JPA annotations in one of two ways, by annotating the fields of the class and also by annotating the get method of the corresponding bean. My question is the following: wit

Hibernate/JPA - Annotating bean methods vs fields

benstpierre: I have a simple question about Hibernate usage. I keep seeing people using JPA annotations in one of two ways, by annotating the fields of the class and also by annotating the get method of the corresponding bean. My question is the following: wit

Avoid annotating @Where clauses in models (Hibernate)

Annoirq I have in my model: @Entity @Where(clause="is_deleted <> '1'") public class Ad { In 95% of cases I will use undeleted ads. However, for one method, I need to get all the removed ads. How can I avoid Whereusing this clause in the query? I am using Crit

Avoid annotating @Where clauses in models (Hibernate)

Annoirq I have in my model: @Entity @Where(clause="is_deleted <> '1'") public class Ad { In 95% of cases I will use undeleted ads. However, for one method, I need to get all the removed ads. How can I avoid Whereusing this clause in the query? I am using Crit

Hibernate/JPA - Annotating bean methods vs fields

Benstpierre : I have a simple question about Hibernate usage. I keep seeing people using JPA annotations in one of two ways, by annotating the fields of the class and also by annotating the get method of the corresponding bean. My question is the following: wi

MatPlotLib key error: 0 when annotating

prom In this code, I'm trying to create a bar chart with one bar (as the "total" bar, which will be placed next to the other bars) and part of a data frame. It works for another slice of the dataframe, but for the "total" slice (only one row), I keep getting t

Syntax when annotating tables in SQL (Oracle)

Mayotte I want to annotate a table in SQL (Oracle) and add a URL to this annotation: comment on table A is 'https://stackoverflow.com/'; But it returns an error: unknown command. What is the correct syntax and how to escape special characters? Jeff Smith simp

With ConcurrentHashMap, when is synchronization required?

For each position: I have a ConcurrentHashMap where I do the following: sequences = new ConcurrentHashMap<Class<?>, AtomicLong>(); if(!sequences.containsKey(table)) { synchronized (sequences) { if(!sequences.containsKey(table)) initial

With ConcurrentHashMap, when is synchronization required?

For each position: I have a ConcurrentHashMap where I do the following: sequences = new ConcurrentHashMap<Class<?>, AtomicLong>(); if(!sequences.containsKey(table)) { synchronized (sequences) { if(!sequences.containsKey(table)) initial

With ConcurrentHashMap, when is synchronization required?

For each position: I have a ConcurrentHashMap where I do the following: sequences = new ConcurrentHashMap<Class<?>, AtomicLong>(); if(!sequences.containsKey(table)) { synchronized (sequences) { if(!sequences.containsKey(table)) initial

Concurrency issues when using ConcurrentHashMap

user4759317: I've been working on a REST API as part of some tricks. The current implementation has a small concurrency issue when inserting objects into the ConcurrentHashMap. My code checks to see if the consumed JSON contains an ID. If not, create a new uni

Concurrency issues when using ConcurrentHashMap

user4759317: I've been working on a REST API as part of some tricks. The current implementation has a small concurrency issue when inserting objects into the ConcurrentHashMap. My code checks to see if the consumed JSON contains an ID. If not, create a new uni

Concurrency issues when using ConcurrentHashMap

user4759317: I've been working on a REST API as part of some tricks. The current implementation has a small concurrency issue when inserting objects into the ConcurrentHashMap. My code checks to see if the consumed JSON contains an ID. If not, create a new uni

JUnit test fails when annotating method arg @Nonnull

Freddy Boucher: Can someone explain why my JUnit tests are failing: notNullMethodTest() using @NotNull -> success nonnullMethodTest() with @Nonnull - > fails Unexpected exception, expected <java.lang.NullPointerException>, but got <java.lang.IllegalArgumentExc

F# undefined type error when annotating variable

Quantum I have a function with a recursive function that counts the letters in a word to "hello"return [|("h",1);("e",1);("l",2);("o",1);|]. My code is as follows: let letterCheck (a:string) = let aList = a |> Seq.toList; let rec _check (charList:char

F# undefined type error when annotating variable

Quantum I have a function with a recursive function that counts the letters in a word to "hello"return [|("h",1);("e",1);("l",2);("o",1);|]. My code is as follows: let letterCheck (a:string) = let aList = a |> Seq.toList; let rec _check (charList:char