Solved the problem. We have an IUserType to map DateTimeOffset properties in UTC in our code to columns of datetime (No datetimeoffset type exists in SQL Server 2005) The Equals method was implemented incorrectly.
Every time the Equals method is called by NH to check for dirty objects, the equals method was returning false even if though the DateTimeOffset values were the same. With this fix in place, the session when autoflushed now only updates entities that were updated, and does not update entities that were not updated! On Wed, Feb 24, 2010 at 3:27 PM, Billy Stack <[email protected]> wrote: > I have traced the call even when the update is unexpected: > > public override bool OnFlushDirty(object entity, object id, object[] > currentState, object[] previousState, string[] propertyNames, > NHibernate.Type.IType[] types) > { > return base.OnFlushDirty(entity, id, currentState, previousState, > propertyNames, types); > } > > I inspected all currentState and previousState and they are exactly the same. > Why would NHibernate attempt to perform OnFlushDirty when "no" state > whatsoever has changed? > > On Wed, Feb 24, 2010 at 1:22 PM, Fabio Maulo <[email protected]> wrote: >> You have Ghosts. >> http://fabiomaulo.blogspot.com/2008/10/how-test-your-mappings-ghostbuster.html >> A ghost may appear because, wrong mapping, stale data (null in DB and not >> nullable property) and so on >> >> 2010/2/24 Billy Stack <[email protected]> >>> >>> All, >>> >>> I have the following scenario: >>> >>> Start Unit of work (SessionFactory.OpenSession()) >>> >>> Get collection of Entities (e.g. 10 in size) from db >>> >>> Update only one entity >>> >>> Dispose the Unit of work (Where we call ISession.Flush()) >>> >>> >>> The problem I am finding is that 10 update statements are generated - >>> one for each entity in the collection, even though I only actually >>> updated one entity. >>> >>> How does NHibernate think that objects in the collection are dirty >>> even though they weren't updated? >>> I am using nullable types, is this the issue? >>> Ref: >>> http://stackoverflow.com/questions/34852/nhibernate-session-flush-sending-update-queries-when-no-update-has-occurred >>> >>> Is this the right way to be using the Session, should I be calling >>> Session.SaveOrUpdate() ? >>> >>> Any help greatly appreciated... >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "nhusers" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/nhusers?hl=en. >>> >> >> >> >> -- >> Fabio Maulo >> >> -- >> You received this message because you are subscribed to the Google Groups >> "nhusers" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/nhusers?hl=en. >> > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
