2.5.2.14. Map Key
JPA supports persistent Map fields through either a OneToMany or ManyToMany association.
The related entities form the map values.
JPA derives the map keys by extracting a field from each entity value.
The MapKey annotation designates the field that is used as the key.
It has the following properties:
-
String name: The name of a field in the related entity class to use as the map key. If no name is given, defaults to the identity field of the related entity class.
The equivalent XML element is map-key which can be listed as a sub-element of the one-to-many or many-to-many elements.
The map-key element has the following attributes:
-
name: The name of the field in the related entity class to use as the map key.