-->
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.  [ 3 posts ] 
Author Message
 Post subject: Ignore null values when updating the database
PostPosted: Mon Jul 16, 2007 5:05 am 
Beginner
Beginner

Joined: Tue May 08, 2007 8:26 am
Posts: 21
Is there any command to ignore empty values when updating the database?

Whenever you call update(); of Session, it will also update the null values found in the object.

Example:

Code:
User user = new User();
user.setUserId( 5);
user.setUserName( "Maarten");
user.setUserFirstName( null);

session.update( user);


The DB will now update the user, but will set the user firstname to null (because it is null in the object).
Is there any way to avoid this? that it will ignore the null value?

I am temporarely fetching the user from the DB now and filling the object with already existing values, but this is one select statement to much tbh.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 10:26 am 
Beginner
Beginner

Joined: Tue May 08, 2007 8:26 am
Posts: 21
Noone knows?
I see that a custom update query would do the trick but that would require alot more work


Top
 Profile  
 
 Post subject: Re: Ignore null values when updating the database
PostPosted: Sun Jun 14, 2009 6:34 am 
Newbie

Joined: Sun Jun 14, 2009 6:20 am
Posts: 7
I need to resolve same problem. Did u find any solution for that?
Or how can resolve that situation?
I need to restrict, only i need, some properties to be updated. So i can't set "updatable=false".
One idea it's to set property to null value. When it's update executed, that property is ignored, but how do that?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.