-->
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: Don't update columns if property was not modified
PostPosted: Thu Aug 03, 2006 4:59 am 
Beginner
Beginner

Joined: Mon Nov 07, 2005 11:10 pm
Posts: 30
Hibernate version: 3.1.2

I looked and searched, this might have been asked before ... but I can't find the exact answer:

Is there a way to tell Hibernate NOT to update columns if the entity's properties were not modified ? That is, if only one property out of ten was modified via a setXXX() method, then it should only update that column on the table ?

Reason I ask are:

1) There are some tables that have update triggers on specific columns. The triggers are being needlessly executed despite the old and new values being the same. Some triggers don't even check the old and new values, generating an audit row in another table, even though that column did not change.

2) Some of the tables have lots of columns ( 10 to 20 columns ). Majority of them are real properties ( not a collection / many-to-one or one-to-many mappings ). It would be good to limit the actual updates to those that were only modified.

Thanks,
John


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 03, 2006 8:16 am 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
In your class element of your mapping file, add the following attribute:

Code:
dynamic-update="true"


with this value set, Hibernate generate an update statement for only the changed fields.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 03, 2006 7:53 pm 
Beginner
Beginner

Joined: Mon Nov 07, 2005 11:10 pm
Posts: 30
Cool. I did not know about that until now. Now why is the default value for this attribute "false", when a default of "true" makes more sense ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 30, 2006 1:21 pm 
Newbie

Joined: Fri Jul 28, 2006 10:53 am
Posts: 15
I'm also curious as to why that's not the case. To maintain consistency with older versions of Hibernate that didn't have that feature?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 01, 2006 4:01 pm 
Beginner
Beginner

Joined: Tue Sep 26, 2006 11:46 pm
Posts: 33
Updating only the changed columns reduces the use of statement caching. If you're always updating the same set of columns then hibernate and the database can cache the update as it's always the same string.

If you only update the changed columns then there is a potential for a different update statement each time so caching is less effective.


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.