-->
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.  [ 2 posts ] 
Author Message
 Post subject: NULL values in Boolean field.
PostPosted: Wed May 17, 2006 12:04 pm 
Newbie

Joined: Fri May 12, 2006 2:29 am
Posts: 3
Hi,

I'm a hibernate novice and am using Core Hibernate 3.

I have a java class, with a member called "nativeFlag", which is of type java.lang.Boolean. (which means that it's nullable). In the mapping file, I haven't explicitly mentioned any type for nativeFlag.

When my table is created, the "nativeFlag" field is stored as a "tinyint" column in my Sybase DB.

Now, when the value in nativeFlag is NULL, I want NULL to be inserted in my DB. However, always 0 gets inserted.

How do I insert NULL in the table, if "nativeFlag" is null?

Need help on this.

Thanks in advance :-)
Harish.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 3:11 pm 
Regular
Regular

Joined: Fri Jul 29, 2005 9:46 am
Posts: 101
Hi!
I don't mean to be rude... but this is the forum for the .NET version of Hibernate... and your question is Java related... so I think it should be posted in : http://forum.hibernate.org/viewforum.php?f=1

Quote:
I have a java class, with a member called "nativeFlag", which is of type java.lang.Boolean. (which means that it's nullable). In the mapping file, I haven't explicitly mentioned any type for nativeFlag.


IMHO having nullable booleans is not advisable... the reason to use "boolean" is because you want to have 2 values "true", and "false" and if you allow a boolean to be nullable... then you have "true", "false" and "unknown" and... well, that is no longer a binary decision... if you are going to have 3 choices for that flag... I really recommend you not to use boolean (from a bussines object model point of view)

Quote:
When my table is created, the "nativeFlag" field is stored as a "tinyint" column in my Sybase DB.


Haven't used Hibernate with Sybase DB... so I just guess that Sybase DB does not have a "bit" type (as SQLServer)

Quote:
Now, when the value in nativeFlag is NULL, I want NULL to be inserted in my DB. However, always 0 gets inserted.

How do I insert NULL in the table, if "nativeFlag" is null?


You mapping file indicates that the field is nullable?


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