BTW, what version of NH the "NHibernate in Actions" describing? 1.2? Or 2.x?

Have you looked at "Audit Log" implementation using event listeners from
more recent versions of NH? It may turn to easier and just better solution.
An example:
http://nhforge.org/wikis/howtonh/creating-an-audit-log-using-nhibernate-events.aspx


On Fri, Aug 20, 2010 at 12:57 AM, Chris J <[email protected]> wrote:

>
> Chapter 8 of the NiA book describes a way to use an IInterceptor
> (actually a subclass of EmptyInterceptor) to audit entity changes. The
> example uses a "temporary session pattern" by using the connection
> from the active session to create a new, temporary session for writing
> a new audit entity:
>
>     foreach(object entity in inserts) {
>             AuditLog.LogEvent(LogType.Create, entity, userId,
> session.Connection);
>     }
>     ...
>
>    public static void LogEvent(
>        LogType logType,
>        object entity,
>        long userId,
>        IDbConnection connection) {
>        using(ISession tempSession =
> sessionFactory.OpenSession(connection)) {
>            AuditLogRecord record = new
> AuditLogRecord(logType.ToString(),
>                                   tempSession.GetIdentifier(entity),
>
> entity.GetType(),
>
> userId);
>
> tempSession.Save(record);
>
> tempSession.Flush();
>        }
>    }
>
> I tried implementing this, but unfortunately it does not work, at
> least not when the top-level session has an active transaction. When I
> implemented it, the Save failed with this exception:
>
>      System.InvalidOperationException : ExecuteNonQuery requires the
> command to have a transaction when the connection assigned to the
> command is in a pending local transaction.  The Transaction property
> of the command has not been initialized.
>
> Looks like this was brought up a couple of years ago:
>
> http://groups.google.com/group/nhusers/browse_thread/thread/f19ff3332da6bf61/e5ed014435abb420
>
> Is this a known issue, and is there a workaround?
>
> --
> 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]<nhusers%[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.

Reply via email to