简体   繁体   中英

Hibernate Session scope in JTA transactions vs Open-Session-In-View

Is it correct to say that using JTA Transactions with H ibernate contrasts using the Open-Session-In-View with regards to the session scope?
From what I've been able to gather the Session scope in the JTA Transactions is a transaction (mainly based on this link ) while in the Open-Session-In-View pattern the session's scope is the requrest and you can have multiple transactions in it.

I'm asking, first to understand, and secondly to verify "Who" is responsible for the session handling when using JTA .
Currently, when using the Open-Session-In-View , I have a HibernateUtil class which handles opening, retrieving and closing of sessions (via ThreadLocal<Session> ).
When I'll switch over to using JTA will Hibernate handle the above session actions? (as a derivative maybe of my calling userTransaction.begin,userTransaction.rollback)

BTW, I'm asking about JTA as I need to coordinate a transaction across Hibernate JMS and EHCache so this isn't a general best-practices "lets-use-JTA" question.

Ittai

Well, if you're using JTA then the JTA manager (usually EJB3 container) is responsible for transactions.

Typically, the same good old open-transaction-in-view model is used, however with UserTransaction and, say, a SWING client it's possible to have long-lasting transactions spanning multiple requests (though it's a bad practice in general).

BTW, I'm asking about JTA as I need to coordinate a transaction across Hibernate JMS and EHCache so this isn't a general best-practices "lets-use-JTA" question.

Good luck. I found that external transaction manager (I've used Atomikos) + Spring worked better for my needs than JBoss.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM