I'm having a real tough time getting this to work. I want to do it properly the first time, so that I can easily persist many different enums in the future (preferably as VARCHARs). The page pointed to most, and the one I'm struggling with currently is this:
http://www.hibernate.org/272.html
Here's my mapping snippet:
Code:
<property name="frequency">
<type name="EnumUserType">
<param name="enumClassName">com.mystuff.Frequency</param>
</type>
</property>
(Isn't this missing a column attribute of some kind?)
When I run hbm2java (still using the one from hibernate2--couldn't find a version for 3), the enum is left out of the class. I tried adding a column, with no success.
The other method I tried was this:
http://www.hibernate.org/265.html
The problem I faced was actually setting the value for the object...ie,
persistentObject.setFrequency( Frequency.DAILY );
did not work, because the setter wanted a FrequencyType (subclass of EnumUserType), not a Frequency enum.
That twiki could stand some cleanup on the topic of persisting enums...I'm sort of suprised this was tossed out for inclusion in Hibernate 3. All of these various EnumUserType implementations are extremely confusing. Or maybe I'm just dumb.