Reputation: 8440
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]
Upvotes: 5
Views: 2771
Reputation: 242686
You cannot use @ManyToMany
with Integer
and Float
because these types are value types, not entities. Use @ElementCollection
(since Hibernate 3.5) or @CollectionOfElements
(in previous versions).
@ElementCollection
Map<Integer,Float> myMap = new HashMap<Integer, Float>();
See also:
Upvotes: 9