-->
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.  [ 7 posts ] 
Author Message
 Post subject: Update only if the property value isn't null
PostPosted: Thu Jul 01, 2004 4:31 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
Is there any way to configure the behavior of the saveOrUpdate method, to update in the db only the non-null properties of the object to be saved??

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 6:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The FAQ has a number of entries on saveAndUpdate

http://hibernate.bluemars.net/116.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 6:46 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
I read it and there isn't any entry that explain what I need to do.
I don't have any exception or so, just a question on how to do something.

Thank you anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 6:51 pm 
Newbie

Joined: Wed Jun 30, 2004 12:47 pm
Posts: 7
Have a look at the dynamic-update attribute of the class element in the hibernate mapping file documentation, I think that is what you are looking for


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 7:39 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
I read it also... the dynamic-update (as I understand it) is to update only the properties that changes, and in my case the property image changes, from a byte[] to null, but I don't want to update if this property is null...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 2:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Not nicely. This could be implemented using either a UserType or an Interceptor.

UserType would be nice because it could be specific to that field. However, you'd have to come up with a way to "know" the current db value since UserType is simply given a PreparedStatement to populate with parameter value(s). But at that point the given column would be included in the PreparedStatement.

The Interceptor approach would work as long as you are not trying this with a detached object. Here, just implement the onFlushDirty() method and move the appropriate value from previousState array to the currentState array if the value in the currentState array is null.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 9:38 am 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
thank you steve!
Do you know where can I find documentation on this topics?


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