JTA和Spring @Transactional注解的区别 [英] Difference between JTA and Spring @Transactional annotations

查看:1555
本文介绍了JTA和Spring @Transactional注解的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用Spring的 @Transactional 标注,并提供了很多方便管理事务。但是,使用此批注在我们的code现在让我们依赖于春季。我知道使用JPA类型的东西有一个的javax持久包,我们可以标记的code与各种如JPA注释,但因为他们都来自 javax.persistence ,我们的code是不依赖于任何特定的实施或ORM。

I've been starting to use Spring's @Transactional annotation, and it provides a lot of convenience for managing transactions. However, using this annotation in our code now makes us dependent on Spring. I know with JPA type stuff there is a javax persistence package where we can mark up the code with all sorts if JPA annotations, but since they all come from javax.persistence, our code isn't dependent on any specific implementation or ORM.

我想我的问题是,如果有事务性的东西任何类似的注解。我发现了一个的javax JTA 包,但我不相信有真的任何通用注解弹簧可以实现。基本上,我只是想知道如果有任何一种通用的javax般的注解,我们可以把方法来管理事务的​​功能,使我们不依赖于春季。

I guess my question is if there are any similar annotations for transactional stuff. I found a javax jta package, but I'm not sure there's really any generic annotations that Spring could implement. Basically I'm just wondering if there's any kind of generic javax-like annotations that we can put on methods to manage transactional functionality so that we aren't dependent on Spring.

推荐答案

我不认为的JavaEE 6提供事务划分的注解像春天一样。最相近的,我想,是利用EJB无状态会话bean,它本质上是事务性的,但没有明确界定为这样的(有人请纠正我,如果我错了)。

I don't think JavaEE 6 offers transaction demarcation annotations like Spring does. The closest analogue, I think, is the use of EJB stateless session beans, which are transactional by nature, but not explicitly demarcated as such (someone please correct me if I'm wrong).

这是你的召唤去哪家API(S),你选择你的夫妇code到。使用的优点Spring的 @Transactional 是,你独立于特定的事务API的使用( @Transactional CAN用JTA,JPA,休眠或原始JDBC事务工作,在不改变code)。但是,当然,你绑春天。

It's your call as to which API(s) you choose to couple your code to. The advantage of using Spring's @Transactional is that you're independent of the specific transaction API being used (@Transactional can work with JTA, JPA, Hibernate or raw JDBC transactions, without changing the code). But, of course, you're tied to Spring.

如果注释风格是你想要的,那么我看不出有什么替代弹簧,除非你想完全接受的JavaEE和使用EJB 3.X风格的标注。

If the annotation style is what you want, then I see no alternative to Spring, unless you want to embrace JavaEE fully and use EJB 3.x-style annotations.

这篇关于JTA和Spring @Transactional注解的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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