-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hinbernate putting NULL for java False boolean ..
PostPosted: Tue Aug 14, 2007 2:53 am 
Newbie

Joined: Tue Oct 17, 2006 10:57 am
Posts: 14
We just took over code from our consultants and have an issue with one of the screen..sorry i am new and might be a dumb question.

The hibernate maping maps the NUMBER(1) column to java Boolean. When the Boolean is false hibernate writes null and when true it write 1 to database.

My reqt is to have 0 value in column when the Boolean flag is FALSE. where can i do it?

Thanks


Last edited by mnsweeps on Tue Aug 14, 2007 10:38 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 3:02 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Quote:
My reqt is to have 0 value in column when the Boolean flag is FALSE

Quote:
When the Boolean is false hibernate writes 0


Sounds like its already behaving the way you want!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 10:38 am 
Newbie

Joined: Tue Oct 17, 2006 10:57 am
Posts: 14
Oops my bad..it was a typo....Currently its writing NULL for FALSE and 1 for TRUE. I want it to write 0 for FALSE instead of NULL.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 12:10 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Are you sure? The hibernate code does this to set boolean values:
preparedStatement.setBoolean( index, ( (Boolean) value ).booleanValue() );
So either you're setting your Boolean property to null in your code or your database/driver is changing false to null. Either way, I don't think hibernate has anything to do with it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 16, 2007 8:18 am 
Newbie

Joined: Thu Aug 16, 2007 3:02 am
Posts: 12
Location: Banglore
for me , for boolean properties 0 is storing for value false.

Any way you can try this

Add the following configuration property in Hibernate.cfg.xml
<property name="hibernate.query.substitutions">true 1, false 0</property>


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