何时使用全局事务或使用spring aop进行事务处理 [英] when to use global transaction Or use spring aop for transaction

查看:274
本文介绍了何时使用全局事务或使用spring aop进行事务处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Q1。我明白当我们需要处理多个数据库时,我们需要使用全局事务。但是从这篇文章 http://fogbugz.atomikos.com/default.asp 。该人建议只使用spring aop来建议不同的transactionmanager(更多> datasource / sessionfactory)。任何人都可以解释什么样的情况下,我们可以使用这种方法吗?在什么样的情况下,我们需要XA(全局事务)与atomikos或jotm或ejb ..等等

如果你指的是这个消息 http://fogbugz.atomikos.com/default.asp?community.6.596.2 ,那么来自OP的问题中的重要部分是:

< blockquote>

该任务可以是一组针对datasource1 datasource2的sql命令。



换句话说,OP不会登记多个事务资源,他将使用其中一个或另一个(并且明确写道他并不需要XA支持)。因此,他并不需要支持全局事务,他只能使用 local 事务,而使用J2EE事务管理器非强制用例。


这就是答案的意思:使用Atomikos不是必要的,可能会过度。

使用两个 dataSource ,两个 txManager ,两个 txAdvice 并定义不同的
< aop:advisor /> 'pointcut'和'advice-ref'属性值将允许将完全不同的事务配置应用于不同的服务层对象/方法。



请参阅 9.5.4。但是如果您需要使用多个事务性资源(通常是关系数据库和消息队列),那么可以使用多个事务性资源您需要全局事务支持,这意味着J2EE事务管理器(由J2EE应用程序服务器提供,或像Atomikos,JBossTS,JOTM等独立提供)。

Q1. i do understand when we need to deal with multiple databases, we need to use global transaction. but from this post http://fogbugz.atomikos.com/default.asp . the person suggested just use spring aop to advise on the different transactionmanager ( more > datasource/sessionfactory). can anyone explain in what kind of situation we can just use this approach And In what kind of situation do we need XA (global transaction) with atomikos or jotm or ejb..etc

解决方案

If you are referring to this message http://fogbugz.atomikos.com/default.asp?community.6.596.2, then the important part in the question from the OP is:

The task can either be a set of sql commands against datasource1 or datasource2.

In other words, the OP won't enlist multiple transactional resources, he will use one or the other (and explicitly writes that he doesn't really need XA-support). So, he doesn't really need global transactions support, he could use local transactions only and using a J2EE transaction manager is not mandatory for his use case.

And this is what the answer is suggesting: using Atomikos is not a necessary and might be overkill.

Using two dataSource, two txManager, two txAdvice and defining distinct <aop:advisor/> elements with differing 'pointcut' and 'advice-ref' attribute values would allow to apply totally different transactional configuration to different service layer objects/methods.

See section 9.5.4. Configuring different transactional semantics for different beans for the details.

But if you need to work with multiple transactional resources (typically relational databases and message queues), then you need global transactions support which means a J2EE transaction manager (provided by a J2EE application server or standalone like Atomikos, JBossTS, JOTM, etc).

这篇关于何时使用全局事务或使用spring aop进行事务处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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