A quick search on Google returns lots of links on how to implement this, one at the topmost is about writing a helping class called EnumUserType.

This solution is outdated as new versions of Hibernate support JPA annotation @Enumerated. Using this former method is much simpler and therefore recommended.

Using @Enumeration annotation:

package org.navalplanner.business.resources.entities;

public enum Status {
BUSY,
AVAILABLE;
}
package org.navalplanner.business.resources.entities;

class MyClass {
@Enumeration(EnumType.VALUE)
private Status status;
}

In the example above, Status and MyClass should be stored in two separate files. Please notice that when doing the Hibernate mapping of class MyClass, if status access policy is set to property, an extra pair of get/set methods should be defined for class MyClass:

@Enumeration(EnumType.VALUE)
public Status getStatus {
return status;
}

@Enumeration(EnumType.VALUE)
public void setStatus(Status status) {
this.status = status;
}

However, I couldn’t get this working using annotations. I don’t know why, maybe* hbm.xml* definition and annotations cannot be mixed. So, I ended up translated this annotation to a hbm.xml file:

<class name="MyClass">
<id name="id">
<generator class="native"/>
</id>

<property name="status">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.igalia.Status</param>
</type>
</property>
</class>

And that’s it!