-->
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 value single row functions
PostPosted: Tue Mar 30, 2004 4:37 pm 
Newbie

Joined: Wed Mar 24, 2004 6:43 pm
Posts: 11
Location: Winnipeg, Manitoba, Canada
Oracle has an NVL function to convert a null field to whatever you want. In the Hibernate Mapping XML file, is there a way to do the same sort of thing?

How would I specify that I wanted the bean value to be populated with 0 if the column field was null, based on the following definition?

<property column="QTY_BO" length="8" name="qtyBo" not-null="false" type="long"/>

Can I do it in the XML file, or does it have to be done in the SQL?

Thanks

_________________
- Dylan Milks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 1:06 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
The question is: when you retrieve a null value from an object and it is converted to a non-null value (in your case null --> 0), do you want this to be persisted in the database?

i.e.
1) db value of x.qtyBo = null
2) load x (value is 0)
3) x.qtoBo saved as 0

If you don't then I would say put this is the method accessor, but don't modify the actual property i.e.
Code:
getQtyBo() {
   if (qtyBo == null) return 0;
   return qtyBo;
}


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.