In my setup I am using Websphere 5 and stateless EJBs for declarative transaction demarcation.
I use the WebsphereTransactionManagerLookup-class to associate with the CMT.
I am trying to get away from the following tedious (and error-prone) method-template :
Session s = HibernateUtil.currentSession();
try {
...
s.flush();
...
finally {
s.close();
}
Instead I am using the TransactionManager and registerSyncronization() so that my sessions
will implicitly be flushed and closed whenever the transaction is completed.
My new methods look like this:
Session s = HibernateUtil.currentSession();
...
and the registered synchronizer contains the method:
public void beforeCompletion() {
log(...);
flushSession();
closeSession();
}
The setup above works fine when the transaction went OK and is commited. I also see a message written to the log.
However, when the transaction is rolled back, it seems as though the synchronizer is never called.
Not beforeCompletion() and not afterCompletion(). No message is written to the log.
Is this a known problem?
Is it a problem at all - nothing saved on a rollback should be pretty OK..?
My only worry is that Session.close() is never called, or maybe Hibernate and Websphere can handle this? `
Perhaps someone even has a better solution to the problem I am trying to solve?
And I know about the Spring-solution... but is there another way?
/Tobbe
|