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