-->
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: JDK 1.5 Enum mapping
PostPosted: Sun Apr 30, 2006 7:21 pm 
Newbie

Joined: Sun Aug 14, 2005 3:08 am
Posts: 5
Hi!

I'm trying to create persistence objects using the new javax.persistence API (JSR 220) and Hibernate (3.2 RC1, EntityManager 3.1 Beta8).

The problem is that I'm trying to map an entity to an existing DB2 table. Unfortunately, the table has a lot of 'Y'/'N' columns that where used for booleans. Ugly.

I tried to build a clean API around this and wanted to use an enum for this. Is there a possibility to map a column value of 'N' to an enum value named MyEnum#NO and 'Y' to YES?

I tried it and currently Hibernate throws an exception because it can't reslove the 'N' to NO.

Thanks,
KM


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 12:25 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
There are several ways to do this. My favourite is to tweak StringValuedEnumType. Have a read of http://www.hibernate.org/273.html.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 8:09 am 
Newbie

Joined: Sun Aug 14, 2005 3:08 am
Posts: 5
Thanks. But is there a way to do it in a JSR220 way, i.e. without using Hibernate classes in my code?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 6:24 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
This doesn't invlolve using hibernate classes in your code. It involves writing code that you put into hibernate. Or rather, that you tell hibernate about. You never use the class that you write, all it does is tell hibernate how to handle your enums. The only reference to the class is in your mapping file.

_________________
Code tags are your friend. Know them and use them.


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.