What’s the best way to persist the following map in a class:
@Entity
class MyClass {
@ManyToMany(cascade = CascadeType.ALL)
Map<Integer,Float> myMap = new HashMap<Integer, Float>();
}
I’ve tried this, but the code results in:
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: mypackage.myClass.myMap[java.lang.Float]
You cannot use
@ManyToManywithIntegerandFloatbecause these types are value types, not entities. Use@ElementCollection(since Hibernate 3.5) or@CollectionOfElements(in previous versions).See also: