Hibernate version:
2.1.3
Hi guys,
I am concerning how to convert the hibernate-based applicaction between JDBC transaction and JTA transaction transparently. And I have explored the hibernate source code and found out that, if we use a JTA transaction, hibernate will lookup a UserTransaction first and check if there is already another JTATransaction existing. If so, hibernate will not create a JTA transaction and join the existing one. So in this way, hibernate propose to make the application which uses hibernate transaction API can switch between JDBC and JTA transaction even CMT transparently without any code changing.
But in my application, I invode hibernate code in a Container Management Transaction Stateless Session Bean which is configured with Required transaction attribute in WAS 5.1. And in WAS 5.1, if a SLSB is CMT, the container will not provide a user transaction. That means we can't lookup a UserTransaction by "java:comp/UserTransaction". There will be an exception said that there is no comp/UserTransaction in java context. But hibernate does use this way to get JTA transaction. And I know I can configure the JTA transaction lookup name in cfg file, but the "jta/usertransaction" doesn't work with SLSB in WAS either.
So any knows how to make these kind of switching without changing code?
Thanks
|