在类中保留以下映射的最佳方法是什么:
@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
with Integer
and Float
因为这些类型是值类型,而不是实体。使用@ElementCollection
(自 Hibernate 3.5 起)或@CollectionOfElements
(在以前的版本中)。
@ElementCollection
Map<Integer,Float> myMap = new HashMap<Integer, Float>();
也可以看看:
- 7.2.3.基本类型和可嵌入对象的集合 http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/collections.html#collections-ofvalues
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)