坚持一个地图<整数,浮点>与JPA [英] Persist a Map<Integer,Float> with JPA
问题描述
@Entity
class MyClass {
@ManyToMany(cascade = CascadeType.ALL)
Map< Integer,Float> myMap = new HashMap< Integer,Float>();
}
我试过这个,但代码的结果是:
引起:org.hibernate.AnnotationException:使用@OneToMany或@ManyToMany以未映射的类为目标:mypackage.myClass.myMap [java.lang.Float]
您不能在 @ManyToMany
> Integer 和 Float
,因为这些类型是值类型,而不是实体。使用 @ElementCollection
(自Hibernate 3.5以来)或 @CollectionOfElements
(在以前的版本中)。
@ElementCollection
地图< Integer,Float> myMap = new HashMap< Integer,Float>();
另请参阅:
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:
这篇关于坚持一个地图<整数,浮点>与JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!