Friday, June 1, 2012

Hibernate: Mapping an Enum

It's done in the mapping file as follows:

<property name="customerType" column="customer_type">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">[insert class name of enum here]</param>
</type>
</property>

Note that due to the limitations of the JPA standards, it only maps to the ordinal, which starts with 0. The only other alternative is to store the String. To do that, add:

<param name="type">12</param>

as the second param inside the "type" tag.


References:

No comments:

Post a Comment