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 @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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With