Package javax.persistence
Annotation Type MapKeyClass
-
@Target({METHOD,FIELD}) @Retention(RUNTIME) public @interface MapKeyClassSpecifies the type of the map key for associations of typejava.util.Map. The map key can be a basic type, an embeddable class, or an entity. If the map is specified using Java generics, theMapKeyClassannotation and associated type need not be specified; otherwise they must be specified.The
MapKeyClassannotation is used in conjunction withElementCollectionor one of the collection-valued relationship annotations (OneToManyorManyToMany). TheMapKeyannotation is not used whenMapKeyClassis specified and vice versa.Example 1: @Entity public class Item { @Id int id; ... @ElementCollection(targetClass=String.class) @MapKeyClass(String.class) Map images; // map from image name to image filename ... } Example 2: // MapKeyClass and target type of relationship can be defaulted @Entity public class Item { @Id int id; ... @ElementCollection Map<String, String> images; ... } Example 3: @Entity public class Company { @Id int id; ... @OneToMany(targetEntity=com.example.VicePresident.class) @MapKeyClass(com.example.Division.class) Map organization; } Example 4: // MapKeyClass and target type of relationship are defaulted @Entity public class Company { @Id int id; ... @OneToMany Map<Division, VicePresident> organization; }- See Also:
ElementCollection,OneToMany,ManyToMany- Since:
- 2.0
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.Classvalue(Required) The type of the map key.
-