-->
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: Children needlessly updated with optimistic locking
PostPosted: Tue Sep 29, 2009 5:09 pm 
Newbie

Joined: Thu Jan 24, 2008 2:40 pm
Posts: 4
Sorry if this has been asked, but it is terribly hard to search for. We are facing a problem with optimistic locking (optimistic-lock="version") and object graphs. We have written tests to prove that if some field or fields in the parent are modified and saveOrUpdate() is called, then the children are ALL updated, even though they haven't been modified. The VERSION number is increased and the "audit fields" are updated. We use custom audit interceptor (extends org.hibernate.EmptyInterceptor) to populate our "created by/when" and "updated by/when" fields. All tables (parents and children) have this audit fields. Collections are mapped with cascade="all, delete-orphan". Anybody see this problem before and have a solution? Any advice on how to figure out why the children are being needlessly updated? Thanks!


Top
 Profile  
 
 Post subject: Re: Children needlessly updated with optimistic locking
PostPosted: Thu Oct 01, 2009 2:26 pm 
Newbie

Joined: Thu Oct 01, 2009 4:55 am
Posts: 4
I would say that this is normal Hibernate behaviour.

You have mapped your collections using cascade="all ..." this tells hibernate that all operations should be cascaded along the association. From Hibernate doc
Quote:
Mapping an association (either a single valued association, or a collection) with cascade="all" marks the association as a parent/child style relationship where save/update/delete of the parent results in save/update/delete of the child or children.


Thats probably why the version gets incremented even though the actual child has not been modified.

For more information read
http://docs.jboss.org/hibernate/stable/core/reference/en/html/objectstate.html#objectstate-transitive


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.