I tried the GetSession(...) sugestion, thanks to Ricardo.

Now it seems to work somehow.

My first try (with the using(...)) didn't run through because the
using closes the session (child AND master). Then I had the problem
that the object change history investigation (I mentioned in my first
mail under 2.) didn't quite work with the childSession. Obviously this
new session has no Information about my object. So I split the change
investigation from the "Save( new ObjectLog(...) )" and now it ran
throught. But again it didn't write to my db... The code is fired, all
my breakpoints hold, but Save(...) has no effect to the db.
Finally I tried to flush the childSession even though the
dokumentiation says to don't do so. And now the ObjectLog-Table is
pupulated. My Code:

public bool OnPreUpdate( PreUpdateEvent evt ) {
    IEntity entity = evt.Entity as IEntity;
    if( entity != null && !( entity is ObjectLog ) ) {
        String changes = ObjectLogHelper.GetChanges( evt.Session,
entity, ObjectLog.ChangeTypes.Update );
        if( changes != "" ) {
            ISession s = evt.Session.GetSession( EntityMode.Poco );
            s.Save( new ObjectLog( entity.GetType().Name, entity.Id,
ObjectLog.ChangeTypes.Update, changes ) );
            s.Flush();
        }
    }
    return false;
}

But now I'm sure that every change that NHibernate tries to write to
my db is logged, even if it is rolled back because of errors of
following objects... Am I right? My logging table will now show undone
changes too.

Maybe collecting all ObjectLogs and writing them to db after the
commit of the current transaction would be more efficient and durable
to rollbacks... Isn't there a PostCommitEvent and PostRollbackEvent or
something similar?

Thanks for any help :-)

-- 
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.

Reply via email to