Hello, I'm writing to ask about some doubts that I have using JTA (BMT) and Hibernate Transaction API.
According to Hibernate reference documentation (3.8.3 - Current Session context management with JTA)
- "If there is no Hibernate Session associated with the current JTA transaction, one will be started and associated with that JTA transaction the first time you call 'sessionFactory.getCurrentSession()'"
- "Your code can either use JTA programmatically through UserTransaction, or (recommended for portable code) use the Hibernate Transaction API to set transaction boundaries"
But, according to section (11.2.2. Using JTA)
- "If you use bean-managed transactions (BMT), Hibernate will tell the application server to start and end a BMT transaction if you use the Transaction API. The transaction management code is identical to the non-managed environment"
- "If you want to use a transaction-bound Session, that is, the getCurrentSession() functionality for easy context propagation, use the JTA UserTransaction API directly"
My doubts according tests that I have made and example codes of section 11.2.2 "BMT idiom, BMT idiom with getCurrentSession()" are:
- If I use JTA "BMT idiom" without using "JTA UserTransaction API" I can't use getCurrentSession() method?
- So, if I want to use getCurrentSession() method I am forced to use the JTA UserTransaction API directly to get the transaction?
- I can't understand the concept of portability using the Hibernate Transaction API if I use the method 'getCurrentSession()' using the "JTATransactionFactory" configuration, because that method force me to use the "JTA UserTransaction API" which precisely introduces the non-portable code:
Code:
UserTransaction trx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction")
This doubts have stucked me and don't let me understand this important part of Hibernate's configuration, hope somebody could help with them.
Regards and Thanks!