-->
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.  [ 6 posts ] 
Author Message
 Post subject: Flushing inconsistencies causing problems with auditing
PostPosted: Wed Sep 19, 2007 7:53 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 11:26 am
Posts: 33
Hi, I am attempting to make use of IInterceptor in order to implement auditing. I'm having problems because when I call ICriteria.UniqueResult<T>(), which forces a flush to occur and therefore my interceptor to fire, the internal state of the entities that have changed doesn't seem to get updated. This means that if/when flush gets called again, my interceptor fires again and I get duplicate entries in my audit log - any thoughts???? It seems like a bug to me.

I presume that that changing the flush mode to "commit" is one way that this problem could be resolved, however, auditing has been bolted on at the end of a sizable project, so I would be reluctant to start changing the flush mode now, since I would be fearful of what else it might break.

Hibernate version: 1.2.0.GA

Name and version of the database you are using: SQLServer 2000

Please find a more detailed explanation of the scenario below:

In the OnFlushDirty method of the interceptor I loop through all of the names in the propertyNames array, I then compare corresponding values in the currentState array and the previousState array and write an entry to the log if there is a difference.

Now consider the following:
Code:
ISession session = NHibernateSessionManager.Instance.GetSession();

Contact contact = session.Get<Contact>(1); // Read contact "Dave"

contact.PreferredName = "Updated preferred name";

session.Flush(); // #### Flush 1 ####

contact.Forename = "Updated forename";

session.Flush(); // #### Flush 2 ####

session.SaveOrUpdateCopy(contact);


In this scenario everything happens as I would expect. When "flush 1" occurs the entries in previousState array and currentState array for the PreferredName field of contact have "Dave" and "Updated preferred name" respectively. There is a difference and therefore an entry is written to the audit log. When "flush 2" occurs the entries in previousState array and currentState array for the Forename field are different, and the entries for PreferredName both have the new value of "Updated preferred name"; this results in one extra audit log entry for the change to the Forename field.

In the scenario I am having a problem with, before "Flush 2" happens I am reading another record using an ICriteria object to build up a query and return the result of ICriteria.UniqueResult<T>(). When UniqueResult() fires it forces a flush which again results in a single audit record being written, however, when "Flush 2" occurs, the internal state doesn't seem to have been updated when UniqueResult() was called. This means that my interceptor fires again, and when the currentState and previousState of the Forename field are compared they are different rather than both having the value "Updated Forename" I therefore end up with two entries in my audit log for the change to the forename field.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 11:38 am 
Newbie

Joined: Mon Feb 19, 2007 5:10 am
Posts: 15
I've had this problem too, but had to work around it.

Anyone know the right answer?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 4:30 am 
Newbie

Joined: Fri Sep 15, 2006 10:18 am
Posts: 8
It sounds to me that NH may be missing some internal clean up.

In the meantime, can you select the last audit entry for the entity type (are you recording such information?) and use that to filter duplicates?

Hopefully someone from the NH team could take a look?

C.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 12:01 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Is this an asp.net app? If so, you can implement the unit of work pattern and change your flush strategy easily then without breaking existing code.

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 4:38 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 11:26 am
Posts: 33
lowecg2004 - I am recording the type of object that is updated in the audit log, so using this as a means of filtering the duplicates is a possibility - I don't like it though :o)

mnichols - It is not an asp.net app.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 6:21 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 11:26 am
Posts: 33
I have now raised a JIRA for this - http://jira.nhibernate.org/browse/NH-1159


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