-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Going crazy trying to persist enums...
PostPosted: Mon Feb 06, 2006 8:18 pm 
Beginner
Beginner

Joined: Fri Jul 15, 2005 12:26 pm
Posts: 37
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 9:17 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The reason that a column mapping isn't needed is because the value of column has a default: the value of name.

You'll need to post classes and exceptions if we're going to help debug this for you. The code on 272.html does work, or at least it did when I copied it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 9:21 pm 
Beginner
Beginner

Joined: Fri Jul 15, 2005 12:26 pm
Posts: 37
I can't as of yet get a java class to be generated from the mapping described above. It generates the class with all the other properties, but the frequency is left out.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 9:51 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
272.html doesn't mention anything about hbm2dll, so I'm betting that you have to fill in the blanks yourself. You'll definitely need to create EnumUserType.java, FrequencyUserType.java and Frequency.java yourself. I don't know if hbm2ddl handles typedefs, but if it does, then I'd set up a frequency typedef, like in the 2nd example on 272.html.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.