简体   繁体   English

JTA事务中的Hibernate Session作用域与View-Open-Session

[英]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? 正确地说,将JTA Transactions与ibernate使用ibernate与使用Open-Session-In-View在会话范围方面形成对比吗?
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. 根据我的能力,在JTA Transactions中收集Session范围是一个事务(主要基于此link ),而在Open-Session-In-View模式中,session的范围就是必需的,您可以在其中进行多个事务。它。

I'm asking, first to understand, and secondly to verify "Who" is responsible for the session handling when using JTA . 我要问的是,首先要理解,其次要验证使用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> ). 当前,当使用Open-Session-In-View ,我有一个HibernateUtil类,用于处理会话的打开,检索和关闭(通过ThreadLocal<Session> )。
When I'll switch over to using JTA will Hibernate handle the above session actions? 当我切换到使用JTA时, Hibernate将处理上述会话操作吗? (as a derivative maybe of my calling userTransaction.begin,userTransaction.rollback) (作为我调用的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. 顺便说一句,我问的是JTA因为我需要在Hibernate JMSEHCache之间协调事务,因此这不是一般的最佳实践“让JTA使用”问题。

Ittai 伊泰

Well, if you're using JTA then the JTA manager (usually EJB3 container) is responsible for transactions. 好吧,如果您使用的是JTA,则JTA管理器(通常是EJB3容器)负责事务。

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). 通常,使用的是相同的,良好的旧的“打开视图中的事务处理”模型,但是对于UserTransaction和SWING客户端,可能有跨多个请求的持久事务(尽管通常这是一种不好的做法)。

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. 顺便说一句,我问的是JTA,因为我需要在Hibernate JMS和EHCache之间协调事务,因此这不是一般的最佳实践“让JTA使用”问题。

Good luck. 祝好运。 I found that external transaction manager (I've used Atomikos) + Spring worked better for my needs than JBoss. 我发现外部事务管理器(我使用过Atomikos)+ Spring可以比JBoss更好地满足我的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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