Jakarta Persistence (JPA) Annotation Type

jakarta.persistence.MapKeyEnumerated

Implemented Interfaces:
Annotation
Target:
Method, Field

Specifies the enum type for a map key whose basic type is an enumerated type.

The MapKeyEnumerated annotation can be applied to an element collection or relationship of type Map<K,V>, in conjunction with the ElementCollection, OneToMany, or ManyToMany annotation. If the enumerated type is not specified or the MapKeyEnumerated annotation is not used, the enumerated type is assumed to be ORDINAL.

Example:

 public enum ProjectStatus {COMPLETE, DELAYED, CANCELLED, IN_PROGRESS}

 public enum SalaryRate {JUNIOR, SENIOR, MANAGER, EXECUTIVE}

 @Entity
 public class Employee {
     @ManyToMany
     public Projects getProjects() { ... }
       
     @OneToMany
     @MapKeyEnumerated(STRING)
     public Map getEmployees() { ... }
     ...
 }
See Also:
Since:
Jakarta Persistence (JPA) 2.0

Annotation Elements

(Optional) The type used in mapping a map key enum type.
Default:
EnumType.ORDINAL
Since:
Jakarta Persistence (JPA) 1.0

Additional JDK methods inherited from java.lang.annotation.Annotation

annotationType(), equals(Object), hashCode(), toString()