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 {
...
}
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
.