-->
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.  [ 8 posts ] 
Author Message
 Post subject: Mapping a Boolean
PostPosted: Wed Nov 16, 2005 8:12 pm 
Newbie

Joined: Tue Mar 15, 2005 1:38 pm
Posts: 11
Hello EJB3 gurus...

Can anyone tell me how I go about mapping a Boolean field in an EJB3 CMP entity bean? I'm trying to map to a database column that's CHAR(1) containing Y/N/null. As far as I can tell the EJB3 spec doesn't address this. Hibernate allows the developer to specify a strategy for mapping object types like this but how do I do this within the EJB3 standard? This seems like something so ridiculously common that I must be missing something?

Thanks,
Corey


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 6:06 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Quote:
4.4.5. Query Language Substitution

You may define new Hibernate query tokens using hibernate.query.substitutions. For example:

hibernate.query.substitutions true=1, false=0

would cause the tokens true and false to be translated to integer literals in the generated SQL.


Set this in the H3 properties.
Then in the db you simply have the smallest integer type (byte?) and in your code normal boolean property.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 8:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
That'd be cool if you EJB3 guys try not to crosspost against JBoss EJB3 forum and this one, this is really a PITA.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 11:47 am 
Newbie

Joined: Tue Mar 15, 2005 1:38 pm
Posts: 11
alesj,

I was looking for something within the EJB3 spec. I take it then, it's not possible? Please not also, I need to map Boolean to Y/N/null not 1/0. These are legacy tables I'm working with.

Thanks,
Corey

alesj wrote:
Quote:
4.4.5. Query Language Substitution

You may define new Hibernate query tokens using hibernate.query.substitutions. For example:

hibernate.query.substitutions true=1, false=0

would cause the tokens true and false to be translated to integer literals in the generated SQL.


Set this in the H3 properties.
Then in the db you simply have the smallest integer type (byte?) and in your code normal boolean property.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 11:49 am 
Newbie

Joined: Tue Mar 15, 2005 1:38 pm
Posts: 11
Emmanual,

I apologize for crossposting. Have you guys considered consolidating the EJB3 forums? It wasn't clear to me that the same experts inhabit both forums. Is one more appropriate than the other?

Corey


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 11:52 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Yeroc wrote:
I need to map Boolean to Y/N/null not 1/0. These are legacy tables I'm working with.


It's the same, use y == 1 and N == 0.
What to use for null?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 1:13 pm 
Newbie

Joined: Tue Mar 15, 2005 1:38 pm
Posts: 11
As far as I can tell from the documentation using query substition is only going to work for querying, not for persisting.

Emmanual replied to my posting on the JBoss ejb3 forum saying that the way to do this is to use the Hibernate-specific @Type(type="yes_no") annotation. It appears this is not addressed by the EJB3 spec in any way. :(

Corey


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 8:10 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This forum is better for people understanding Hibernate from the ground and wanting to switch.
The other one is better for pure EJB3 players from the ground.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.