-->
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.  [ 4 posts ] 
Author Message
 Post subject: Dirty check and versioning question
PostPosted: Wed Sep 13, 2006 9:48 am 
Newbie

Joined: Wed Sep 06, 2006 4:23 am
Posts: 6
Hello,

I have a general question about the dirty check ...

A simple scenario:

DataObject DoWfInstance with children of type DoWfInstance
(Lazy Loading enabled, Versioning enabled)

Code:
using (NHibernate.ISession session = _nhFactory.OpenSession(new Interceptor(new SaveInterceptor())))
{
   DoWfInstance instance = (DoWfInstance)session.Get(typeof(DoWfInstance), (long)224);
   Console.WriteLine(instance);
   foreach (DoWfInstance child in instance.Children)
   {
      //child.ChangeDate = DateTime.Now;
      Console.WriteLine(child);
   }
   DoWfInstance c0 = CollectionUtil.GetItemAt<DoWfInstance>(instance.Children, 0);
   Console.WriteLine("child: " + c0);
   instance.Children.Remove(c0);
   using (NHibernate.ITransaction t = session.BeginTransaction())
   {
      session.Flush();
      t.Rollback();
   }
}



Why is nHibernate updating (database update statement) the parent object (ID 224) on commit?
My implementation of the interceptor returns OnDirtyCheck no changed fields and the database record is not changed at all (except the version field is increased), only an entry of the child collection is removed.



I have checked the SessionImpl.cs of nHibernate ...
In IsUpdateNecessary there is the following check:
Code:
if( status == Status.Loaded && persister.IsVersioned && persister.HasCollections )
{
   DirtyCollectionSearchVisitor visitor = new DirtyCollectionSearchVisitor( this );
   visitor.ProcessValues( values, types );
   return visitor.WasDirtyCollectionFound;
}


The visitor.WasDirtyCollectionFound returns true because the Children are dirty.

If I disable the versioning for the mapping, no update is executed.

It is a big problem for us, because the parent instance (ID 224) is updated in another thread, so I get a VersioningException.


My only idea is to remove the parent instance (ID 224) from session, but I don't think that this is the solution for the problem, it's only a workaround.

What is the background for updating this record?

Regards
Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 9:57 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Collections are thought of as belonging to the object that contains them (similarly to "plain", scalar properties). Thus any modification of a collection is considered a modification in the state of the parent object and will cause the parent's version to be incremented.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 10:02 am 
Newbie

Joined: Wed Sep 06, 2006 4:23 am
Posts: 6
sergey wrote:
Collections are thought of as belonging to the object that contains them (similarly to "plain", scalar properties). Thus any modification of a collection is considered a modification in the state of the parent object and will cause the parent's version to be incremented.



There are a lot of updates required and this seems to be very inperformant.

So this behaviour is by design and can not be changed, right?

Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 04, 2007 9:50 am 
Newbie

Joined: Mon Jul 18, 2005 9:04 am
Posts: 11
I have just come accross the same issue as well.
I can completely understand the thinking behind the design as it makes sense, but I wonder if there would be value in making it "user defined", either on a session base or in configuration. That way, you could still use versioning, but in performance critical scenarios the user can decide which version method to use ("all" as the default, or "changed entitiy only").

Would this be useful? If so, I may try to implement this and submit it as a patch.


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