坚持一个地图<整数,浮点>与JPA [英] Persist a Map<Integer,Float> with JPA

查看:99
本文介绍了坚持一个地图<整数,浮点>与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:

这篇关于坚持一个地图&lt;整数,浮点&gt;与JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆