Hibernate version: 3
I've been using Session.currentSession() to get the current managed
transaction (I actually use a helper class that substitutes openSession()
for unit tests).
I'm looking at performing some audit capabilities using events and/or interceptors. I've read most of the forum topics on auditing
and all of them seem to use interceptors that are added at session creation time.
They have something like:
Code:
String user = getUserSomehow();
Interceptor i = new MyInterceptor(user);
Session session = factory.openSession(i);
What I'm looking for is something like:
Code:
String user = getUserSomehow();
Interceptor i = new MyInterceptor(user);
Session session = factory.currentSession(i);
This would use the interceptor if it needed to create a new session.
The only other way I can see to do this is to put a lot of work into the interceptor. I would have to do the following:
Assign the cuid to the current JTA transaction
Specify the interceptor in the configuration
Have the interceptor grab the user name from the JTA transaction
That seems like a
lot of work. Does anyone have a better idea of logging the user name when using container managed sessions?
John