Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Enumerated"
m |
m |
||
Line 56: | Line 56: | ||
{{EclipseLink_JPA | {{EclipseLink_JPA | ||
− | |previous=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings|Basic | + | |previous=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Basic|@Basic]] |
|next= [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Temporal|@Temporal]] | |next= [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Temporal|@Temporal]] | ||
|up= [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings|Basic Mappings]] | |up= [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings|Basic Mappings]] | ||
|version=2.2.0 DRAFT}} | |version=2.2.0 DRAFT}} |
Revision as of 12:43, 15 February 2011
EclipseLink JPA
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
@Enumerated
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.
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 Usage of the @Enumerated Annotation example, 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. |
No |
Given the enumerated constants in the Enumerated Constants example, the Usage of the @Enumerated Annotation example 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.
Enumerated Constants
public enum EmployeeStatus {FULL_TIME, PART_TIME, CONTRACT} public enum SalaryRate {JUNIOR, SENIOR, MANAGER, EXECUTIVE}
Usage of the @Enumerated Annotation
@Entity public class Employee implements Serializable{ ... public EmployeeStatus getStatus() { ... } @Enumerated(STRING) public SalaryRate getRate() { ... } ... }
For more information, see Section 9.1.21 "Enumerated Annotation" in the JPA Specification.
![]() |
@Temporal![]() |
|
![]() JPA User Guide: |
||
How to contribute to this guide... |