简体   繁体   中英

Annotation a Map containig a non-entity class in JPA

Is it possible to use a map with a non-entity class in 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. 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.

JPA 2.0 will provide similar functionality with @ElementCollection .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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