Jakarta Persistence (JPA) Annotation Type
jakarta.persistence.Enumerated
- Implemented Interfaces:
Annotation
- Target:
- Method, Field
Specifies that a persistent property or field should be persisted as an enumerated type. This annotation is optional if the type of a persistent field or property is a Java
enum type. The Enumerated annotation may be used in conjunction with the Basic annotation, or in conjunction with the ElementCollection annotation when the element 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 persistent field or property of enum type has no explicit Enumerated annotation, and if no converter is applied to the field or property:
- 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 EmployeeStatus {FULL_TIME, PART_TIME, CONTRACT} public enum SalaryRate {JUNIOR, SENIOR, MANAGER, EXECUTIVE} @Entity public class Employee { public EmployeeStatus getStatus() { ... } ... @Enumerated(STRING) public SalaryRate getPayScale() { ... } ... }
- See Also:
- Since:
- Jakarta Persistence (JPA) 1.0
The JPA Persistable Types article explains how to use
Enumerated.Annotation Elements
Additional JDK methods inherited from java.lang.annotation.Annotation
annotationType(), equals(Object), hashCode(), toString()