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.  [ 12 posts ] 
Author Message
 Post subject: How do you map a boolean in Oracle
PostPosted: Mon Jul 17, 2006 2:38 pm 
Newbie

Joined: Wed Jul 12, 2006 5:27 pm
Posts: 4
All,

I have used nHibernate in the past with SQL Server with great success, and have now embarked on an Oracle project. My business objects, of course, have boolean properties. Since Oracle does not have a "bit" data type like SQL Server, what is the recommended method for handling this?

I have tried mapping to NUMBER(1,0), but get a cast exception. I have also tried a CHAR(1) with the same results. I am trying to avoid a lot of clunky code to work around this, so is there something already provided that I am just missing?

Any help is GREATLY appreciated.

Thank you,

_________________
Phil Pastor


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 7:17 pm 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
You are totally on the right path. I use NUMBER(1) with Oracle, but I think NUMBER(1,0) should work.

Are you now using the OracleDialect?

Code:
hibernate.dialect=org.hibernate.dialect.OracleDialect


I think that is all you need to do to substitute TRUE => 1 and FALSE => 0. And then you map the fields as "boolean" in your hibernate config files and in your Java objects.

Is this what you are doing and it's not working?

_________________
_________________
dan

If what I say is helpful, please rate the post as such by clicking 'Y'. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 10:14 pm 
Newbie

Joined: Wed Jul 12, 2006 5:27 pm
Posts: 4
Dan,

Thanks for the reply.

Upon further review, it does work just fine with normal booleans. My issue is with the Nullables. As soon as I switch the mapping file over to the NullableBooleanType I get the cast exception IF there is a value in the database. If the value in the db is null, then it is fine.

Any thoughts?

Phil

_________________
Phil Pastor


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 2:11 am 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
I have not worked with those objects, but some things come to mind. Are you using java.lang.Boolean objects for your mapping types and Java fields? (as opposed to the primitive 'boolean' type)

_________________
_________________
dan

If what I say is helpful, please rate the post as such by clicking 'Y'. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 7:38 am 
Newbie

Joined: Wed Jul 12, 2006 5:27 pm
Posts: 4
This is a .NET 2.0 application, and I am using the nullable boolean (bool?).

_________________
Phil Pastor


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 11:15 am 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
Sorry about that. I ended up in the NHibernate forum without realizing it when viewing unanswered posts.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 11:49 am 
Newbie

Joined: Tue Apr 25, 2006 8:08 am
Posts: 2
How map 'Y'/'N' chars to NHibernate?
Unfortunetly I can't change database :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 11:53 am 
Newbie

Joined: Tue Apr 25, 2006 8:08 am
Posts: 2
How map 'Y'/'N' (varchar2(1)) chars to NHibernate?
Unfortunetly I can't change database :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 12:34 pm 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
<prop key="hibernate.query.substitutions">true Y, false N</prop>

_________________
_________________
dan

If what I say is helpful, please rate the post as such by clicking 'Y'. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 1:06 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
As far as I know, all you should have to do is the following. I haven't tried boolean with Oracle specifically, but, I did something similar with with a nullable DateTime. Basically, I think you just tell the the .NET type (for nullables). I'm not sure if this is even necessary at this point. I got it to work this way, but, when I did that it was with a nightly build from awhile ago. Maybe it can detect better now. You shouldn't have to specify database specific types. The dialect should take care of that for you.

Code:
<property name="MyBoolean" type="System.Boolean"/>


--Please rate me if this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 5:17 pm 
Beginner
Beginner

Joined: Wed Jun 01, 2005 3:22 pm
Posts: 38
Location: Menlo Park, CA
I just use type="YesNo".

Code:
      <property name="Cancelled" type="YesNo" length="1" not-null="true"/>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 8:18 pm 
Newbie

Joined: Wed Jul 12, 2006 5:27 pm
Posts: 4
What is a YesNo type?

_________________
Phil Pastor


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