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: Empty persistent bag causing object to be treated as dirty
PostPosted: Thu Aug 07, 2008 5:58 pm 
Newbie

Joined: Tue Jul 15, 2008 2:50 pm
Posts: 2
Location: Maryland
Hibernate version: 1.2.0.2002

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: SQL Sever 2005

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling? No

We have a mapping document where an association is mapped as follows:

<bag name="Segments" access="field.camelcase-underscore" cascade="all">
<key column="TRIP_ID" />
<one-to-many class="SegmentImpl"/>

An instance of the class containing this collection is loaded. The collection is empty (i.e. it is non-null but has no items). No changes are made and the object is saved. On flushing the session, SessionImpl.IsUpdateNecessary(persister, cannotDirtyCheck, status, dirtyProperties, values, types) returns true, indicating the object is dirty and needs saving. Stepping through this function the visitor that looks at each property finds the bag and gets it's collection entry. The collection entry has a dirty flag set which is why IsUpdateNeccessary returns true.

Can someone explain this? We have a collection that is empty on retrieval and empty on saving so why is it considered dirty?

I have verified that if I comment out the association shown above from the HBM and save no updates occur.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 2:37 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Does that happen during a normal session flush or do you have a detached object that you are reattaching with Update() or SaveOrUpdate() ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 10:54 am 
Newbie

Joined: Tue Jul 15, 2008 2:50 pm
Posts: 2
Location: Maryland
The containing object is transient and has been made persistent through a call to ISession.SaveOrUpdateCopy. The flush mode is "never" so after this call (as part of a decorator chain unwind) an explicit flush is called on the sesssion. It is in the processing of the flush that we see NHibernate detecting the Segments bag as dirty for every domain object existing before the new one was added causing an update to every corresponding row in the database.

A little more information we have after digging further. We have an interceptor that updates a couple of auditing columns in the database. This fires after NHibernate has determined the object is dirty. Subesequently there is code to build a collection of the indexes of the properties that are dirty. What we see is NHibernate only detects the 2 columns the interceptor changed as being dirty. Hence, at one point in the code the Segments bag is considered dirty, in a later part of the code it is not.

Hope this helps. As you can probably infer the problem is our auditing information is getting wiped out whenever a new domain object is added which is a big problem for us.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 09, 2008 7:52 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
When you call session.Update() on a transient object, afaik hibernate will always send updates to the db. I think you can prevent that with specifying select-before-update on the class mapping or by using version/timestamp properties.

_________________
--Wolfgang


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.