views:

38

answers:

1

I have a problem with the DefaultUpdateEventListener in NHibernate. I will update 2 objects and then i commit the session.

The first object didn't come into the listener and the second object comes there.

So i checked with reflector to check what the problem is

First NHibernate will call the PerformSaveOrUpdate in the DefeultSaveOrUpdateEventListener there i see this

protected virtual object PerformSaveOrUpdate(SaveOrUpdateEvent @event)
{
    switch (this.GetEntityState(@event.Entity, @event.EntityName, @event.Entry, @event.Session))
    {
        case EntityState.Persistent:
            return this.EntityIsPersistent(@event);

        case EntityState.Detached:
            this.EntityIsDetached(@event);
            return null;
    }
    return this.EntityIsTransient(@event);
}

The differens of both object is the state The first object is detached and the second persistent

What makes a object persistent or detached in NHibernate ?

If i know what the difference is in this example i hope i can fix this in my code.

The load of both object are equal with session.Load

+1  A: 

I resolved the problem to implement the
public override void OnSaveOrUpdate(SaveOrUpdateEvent @event)

This event will be hit before the PerformSaveOrUpdate(SaveOrUpdateEvent @event)

On this time it doesn't matter if the object is persistent or detached

Marco