Thanks for the quick answer. I tried it but it seems not to go into the same transaction (Hibernate 2.1.3), at least not the way I do it:
Session / interceptor creation:
Code:
AuditLogInterceptor i = new AuditLogInterceptor(userId);
session = this.sessionFactory.openSession(i);
i.setAuditLogSession(sessionFactory.openSession(session.connection());
Transaction tx = session.beginTransaction();
...
AuditLogInterceptor: onFlushDirty() / onSave()
Code:
...
auditLogSession.save(logObject);
auditLogSession.flush(); // needed otherwise save() is ignored
...
The auditLogSession is closed when the (primary) session is closed.
Two things that indicate that I am missing the transaction:
1) I need to flush() the second session after each save() otherwise the log objects are not created in the database. This should not be necessary.
2) If the transaction fails and is rolled back the (flushed) log object remains in the database.
Same is true for onSave() (which I need too, of course).
What am I missing?
Thank you in advance,
Thomas