Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: for the plan.

Jump to: navigation, search

EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Enumerated

< EclipseLink‎ | UserGuide‎ | JPA‎ | Basic JPA Development‎ | Mapping‎ | Basic Mappings
Revision as of 10:51, 27 October 2011 by (Talk | contribs) (Example: @Enumerated Annotation)

EclipseLink JPA

Mailing ListForumsIRCmattermost
OpenHelp WantedBug Day
Browse Source

Elug api package icon.png Key API


By default, EclipseLink persistence provider persists the ordinal values of enumerated constants.

Use the @Enumerated annotation to specify whether EclipseLink persistence provider should persist ordinal or String values of enumerated constants if the String value suits your application requirements, or to match an existing database schema:

You can use this annotation with the @Basic annotation.

@Enumerated Attributes
Attribute Description Default Required?
value By default, EclipseLink persistence provider assumes that for a property or field mapped to an enumerated constant, the ordinal value should be persisted. In the @Enumerated Annotation example, below, the ordinal value of EmployeeStatus is written to the database when Employee is persisted.
If you want the String value of the enumerated constant persisted, set value to EnumType.STRING.

Given the enumerated constants in the Enumerated Constants example, the @Enumerated Annotation example, below, shows how to use the @Enumerated annotation to specify that the String value of SalaryRate should be written to the database when Employee is persisted. By default, the ordinal value of EmployeeStatus is written to the database.

Example: Enumerated Constants
public enum EmployeeStatus {FULL_TIME, PART_TIME, CONTRACT}
Example: @Enumerated Annotation
public class Employee implements Serializable{
    public EmployeeStatus getStatus() {
    public SalaryRate getRate() {
Elug javaspec icon.gif

For more information, see Section 9.1.21 "Enumerated Annotation" in the JPA Specification.

Legacy Data

Another option for mapping enumerated values is to use an ObjectTypeConverter. A converter allows for type codes to be used on the database instead of the enum's name, which may be required for legacy data.

See, ObjectTypeConverter

Version: 2.2.0 DRAFT
Other versions...

Back to the top