[hibernate-dev] Hibernate 4.x, JTA(BMT) transactions no longer interchangeable with Hibernate transaction facade?
zackurey at gmail.com
Wed May 9 13:47:04 EDT 2012
Am I correct in my interpretation that Hibernate 4 no longer supports
interchangeably being able to use either the Hibernate transaction
facade(session.beginTransaction) vs. UserTransaction or CMT?
I say this because it appears that I always must call
session.beginTransaction() when configured to use
JTATransactionFactory, in order to have JtaTransaction->local status
of active. If local status is not active Hibernate makes no attempt
to check the provided JtaPlatform if there is a user transaction in
process and blows up whenever trying to execute any changes to the db.
In 3.x this worked fine since
JTATransactionFactory->isTransactionInProgress always tried to find
the configured transaction manager and checked the transaction status
properly. But in 4.x I'm not seeing how local status gets set to
active to prevent a blow up unless I both call userTransaction.begin()
AND session.beginTransaction()... The same problems exist when
interacting through the EntityManager API.
Even in the ManagedDrivingTest it looks like it is assumed that the
client will call session.beginTransaction() after either a CMT or BMT
has been started. I would cut over to using the Hibernate facade
exclusively, but now it throws 'nested transactions not supported' if
beginTransaction is invoked multiple times. The Spring
PlatformTransactionManager API deals with multiple layered invocations
more gracefully, so I've mostly used that in the past for programmatic
transaction management. But regardless, looking at the source there
seems to be a new requirement to always have
session.beginTransaction() invoked in application code.
I've spent days trying to figure out if I've made a configuration
mistake, and at this point I'm at the conclusion that either Hibernate
behavior in this area was intentionally changed, or that this is a
bug. If its a bug it would probably break a lot of apps upgrading
from 3.x to 4.x that use programmatically controlled transactions. So
I thought I'd just reach out on the mailing list for clarification, or
to have an obvious misconfiguration or misunderstanding corrected.
For more info on my JTA config there is a forum post I made that is
unrelated(realized my error on that topic) here:
More information about the hibernate-dev