是否使用JTA交易? [英] use JTA transaction or not?

查看:133
本文介绍了是否使用JTA交易?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发部署在JBoss应用服务器上的J2EE应用程序。
应用程序由EJB 2.x组件和Web组件组成,并在本地计算机或远程服务器上运行。数据库是Oracle或SQL Server,不在分布式环境中。



我正在使用Hibernate 3.6(JPA 2.0实现)进行事务处理。我应该使用JTA是容器管理的交易还是过度使用它?



目前我正在使用JTA,事实证明它运行正常,但有一些小问题,我不知道它是否与事务管理有关。使用本地事务管理会更容易或更可靠吗?

解决方案

JTA事务总是推荐使用其他类型的事务API,特别是如果您指的是仍然是JPA API一部分的本机交易。请注意,您不能说'JTA对资源本地交易',因为JTA实际上管理资源本地交易。



Gavin King(Hibernate的创建者)曾经指出接受采访时表示,JPA具体的API是一个错误,而且更加灵活的JTA API应该是首选。特别是当使用声明式事务时,JTA非常轻量级。 overkill 这个词实际上应用更多的是使用JPA原生事务API,然后使用JTA。



关于使用XA或资源本地事务与JTA之间的选择。有关这方面的更多细节,请参阅我的答案: JPA2 + Hibernate 3.6.0中的JTA或LOCAL事务?



我不知道为什么要使用EJB 2与JPA 2.0结合使用。 EJB 3.1将是一个更合乎逻辑的选择。 EJB 2已完全弃用(将在Java EE 7中修剪)。


I am developing a J2EE application which is deployed on JBoss application server. The application is composed of an EJB 2.x component and a web component and is running on local computer or remote server. The database is either Oracle or SQL Server and is not in a distributed envrionment.

I am using Hibernate 3.6 (JPA 2.0 implementation) for the transactions. Should I use JTA which is container managed transaction or is it overkilled to use it?

Currently I am using JTA and it turns out it is running fine but with some small issues which I do not know whether it is related to the transaction management or not. Will it be easier or more reliable to use local transaction management?

解决方案

JTA transactions are always recommended above other kinds of transaction APIs, especially if you are referring to the native transactions that are still part of the JPA API. Note that you can't say 'JTA vs resource local transactions', as JTA actually manages resource local transactions among others.

Gavin King (creator of Hibernate) once indicated in an interview that this JPA specific API was a mistake and that the much more flexible JTA API should be preferred. Especially when using declarative transactions, JTA is very lightweight. The word overkill would actually apply more to using the JPA native transaction API, then to using JTA.

There is something to say about the choice between using XA or resource local transactions with JTA. See my answer here for some more details about that: JTA or LOCAL transactions in JPA2+Hibernate 3.6.0?

I do wonder why you are using EJB 2 in combination with JPA 2.0. EJB 3.1 would be a much more logical choice here. EJB 2 is completely deprecated (will be pruned in Java EE 7).

这篇关于是否使用JTA交易?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆