NHibernate's automatic (dirty checking) update behaviour - turning it off

Posted by Andrew Bullock on Stack Overflow See other posts from Stack Overflow or by Andrew Bullock
Published on 2009-03-23T14:23:31Z Indexed on 2010/05/27 11:51 UTC
Read the original article Hit count: 430

Filed under:

I've just discovered that if I get an object from an NHibernate session and change a property on object, NHibernate will automatically update the object on commit without me calling Session.Update(myObj)!

I can see how this could be helpful, but as default behaviour it seems crazy!

How can I stop this happening? Is this default NHib behaviour or something coming from Fluent NHibs AutoPersistenceModel?

If there's no way to stop this, what do I do? Unless I'm missing the point this behaviour seems to create a right mess, violating my UoW.

Im using NHibernate 2.0.1.4 and a Fluent NHib build from 18/3/2009

Edit, is this guy right with his answer?

Edit: I've also read that overriding an Event Listener could be a solution to this. However, IDirtyCheckEventListener.OnDirtyCheck isn't called in this situation. Does anyone know which listener I need to override?

Thanks

Andrew

© Stack Overflow or respective owner

Related posts about nhibernate