简体   繁体   English

注释包含 JPA 中的非实体类的 Map

[英]Annotation a Map containig a non-entity class in JPA

Is it possible to use a map with a non-entity class in JPA?是否可以在 JPA 中使用带有非实体类的地图? If yes, how should it be annotated correctly?如果是,应该如何正确注释?


@Entity
class A {

   @HowShouldIAnnotateThis?
   private Map<B, Integer> myMap = new HashMap<B, Integer>();

}

@Entity
class B {
 ...
}

You cannot do this with JPA 1.0.您不能使用 JPA 1.0 执行此操作。 Some implementations provide proprietary extensions (such as EclipseLink's @BasicMap ) which you could use if you don't mind coupling your application to the given JPA provider.某些实现提供专有扩展(例如 EclipseLink 的@BasicMap ),如果您不介意将应用程序耦合到给定的 JPA 提供程序,则可以使用这些扩展。

JPA 2.0 will provide similar functionality with @ElementCollection . JPA 2.0 将提供与@ElementCollection类似的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM