Sunday, April 6, 2014

Hibernate mapping to enum

Enum can be used directly in domain object.


Hibernate will save ordinal of the enum into database. FULL_TIME_EMPLOYEE is 0, PART_TIME_EMPLOYEE is 1... Hmm.... How about a new enum value is added between FULL_TIME and PART_TIME, the ordinal of PART_TIME will be changed to 2.
Use the annotation @Enumerated(EnumType.STRING), which will let hibernate save the string value of the enum.

No comments:

Post a Comment