[英]Persist a Map<Integer,Float> with JPA
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] 引起:org.hibernate.AnnotationException:使用@OneToMany或@ManyToMany定位未映射的类:mypackage.myClass.myMap [java.lang.Float]
You cannot use @ManyToMany
with Integer
and Float
because these types are value types, not entities. 您不能将
@ManyToMany
与Integer
和Float
一起使用,因为这些类型是值类型,而不是实体。 Use @ElementCollection
(since Hibernate 3.5) or @CollectionOfElements
(in previous versions). 使用
@ElementCollection
(自Hibernate 3.5起)或@CollectionOfElements
(在以前的版本中)。
@ElementCollection
Map<Integer,Float> myMap = new HashMap<Integer, Float>();
See also: 也可以看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.