Save map <Integer, Float> with JPA

What is the best way to save the following map in class:

@Entity class MyClass { @ManyToMany(cascade = CascadeType.ALL) Map<Integer,Float> myMap = new HashMap<Integer, Float>(); } 

I tried this, but as a result of the code:

Called: org.hibernate.AnnotationException: using @OneToMany or @ManyToMany to target an unmarked class: mypackage.myClass.myMap [java.lang.Float]

+4
source share
1 answer

You cannot use @ManyToMany with Integer and Float , because these types are value types, not entities. Use @ElementCollection (starting with Hibernate 3.5) or @CollectionOfElements (in previous versions).

 @ElementCollection Map<Integer,Float> myMap = new HashMap<Integer, Float>(); 

See also:

+9
source

Source: https://habr.com/ru/post/1337747/


All Articles