Ok, so then something is very odd because 1) In OnPostLoad(), 1-a) I'm resetting the entity (via Reset()@https://github.com/sidshetye/NHMarkEntityClean/blob/master/NHListeners.cs#L72) 1-b) I'm verifying if entity is unchanged (via your code@https://github.com/sidshetye/NHMarkEntityClean/blob/master/SessionUtils.cs#L11) => Seems Reset() is doing it's job
2) Despite this reset, OnFlushEntity() gets called on this seemingly unchanged entity! I've created a self-sufficient test project at https://github.com/sidshetye/NHMarkEntityClean which demonstrates this issue. The local database etc is all setup, you can simply run it and see the phantom FlushEvent being called on the entity when it shouldn't have (because we just reset it properly). I looked inside NH at AbstractFlushingEventListener.cs, FlushEntities() and see that the entity we had just reset earlier (1-a) still appears in the ICollection list - these seems to be no dirty checks performed despite a comment on the method saying there should be one. I'm not an expert on this but if everything pieces together, wouldn't this be a bug in NHibernate? If it's not a bug in NHibernate, what would make the test pass (i.e. no flushes for "unchanged" entities?) // 1. detect any dirty entities // 2. schedule any entity updates // 3. search out any reachable collections protected virtual void FlushEntities(FlushEvent @event) { log.Debug("Flushing entities and processing referenced collections"); // Among other things, updateReachables() will recursively load all // collections that are moving roles. This might cause entities to // be loaded. // So this needs to be safe from concurrent modification problems. // It is safe because of how IdentityMap implements entrySet() IEventSource source = @event.Session; ICollection list = IdentityMap.ConcurrentEntries(source.PersistenceContext.EntityEntries); foreach (DictionaryEntry me in list) { // Update the status of the object and if necessary, schedule an update EntityEntry entry = (EntityEntry) me.Value; Status status = entry.Status; if (status != Status.Loading && status != Status.Gone) { FlushEntityEvent entityEvent = new FlushEntityEvent(source, me.Key, entry); IFlushEntityEventListener[] listeners = source.Listeners.FlushEntityEventListeners; foreach (IFlushEntityEventListener listener in listeners) { listener.OnFlushEntity(entityEvent); } } } source.ActionQueue.SortActions(); } -- --- You received this message because you are subscribed to the Google Groups "nhibernate-development" group. To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-development+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.