Annotation Interface MapKeyEnumerated
Specifies that a map key should be persisted as an enumerated type.
The declared type of the annotated property or field must be
Map<K,V> where K is a Java enum type. This
annotation is always optional.
The MapKeyEnumerated annotation may be used in conjunction
with the ElementCollection annotation, OneToMany
annotation, or ManyToMany annotation when the key type of the
collection is an enum type.
An enum can be mapped as either a string or an integer, where
EnumType enumerates the available options. The mapping
may be explicitly specified by this annotation.
If a map key of enum type has no explicit MapKeyEnumerated
annotation, and if no converter is applied to the key:
- if the enum type has a final field of type
StringannotatedEnumeratedValue, the enumerated type is inferred to beEnumType.STRING; - otherwise, the enumerated type is taken to be
EnumType.ORDINAL.
Example:
public enum ProjectStatus {COMPLETE, DELAYED, CANCELLED, IN_PROGRESS}
public enum SalaryRate {JUNIOR, SENIOR, MANAGER, EXECUTIVE}
@Entity
public class Employee {
@ManyToMany
public Projects<ProjectStatus, Project> getProjects() { ... }
@OneToMany
@MapKeyEnumerated(STRING)
public Map<SalaryRate, Employee> getEmployees() { ... }
...
}
- Since:
- 2.0
- See Also:
-
Optional Element Summary
Optional Elements
-
Element Details
-
value
-