Java 带有 jta="true" 的 nonXADatasource 和 XADataSource 之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27781024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between nonXADatasource with jta="true" and XADataSource?
提问by user3663882
I was confused by the fact that we can allow to use JTA transactions with a non-XA-datasource. Link to the documentation. So what is the difference between XA/non-XA datasources? Why should we use XA-datasources at all?
我对我们可以允许将 JTA 事务与非 XA 数据源一起使用这一事实感到困惑。链接到文档。那么 XA/非 XA 数据源之间的区别是什么?我们为什么要使用 XA 数据源?
采纳答案by ashokhein
An XA transaction, in the most general terms, is a "global transaction" that may span multiple resources. A non-XA transaction always involves just one resource.
An XA transaction involves a coordinating transaction manager, with one or more databases (or other resources, like JMS) all involved in a single global transaction. Non-XA transactions have no transaction coordinator, and a single resource is doing all its transaction work itself (this is sometimes called local transactions).
一个 XA 事务,在最一般的术语中,是一个可能跨越多个资源的“全局事务”。非 XA 事务总是只涉及一种资源。
一个 XA 事务涉及一个协调事务管理器,一个或多个数据库(或其他资源,如 JMS)都包含在单个全局事务中。非 XA 事务没有事务协调器,单个资源自己完成所有事务工作(有时称为本地事务)。
Note: The explanation above was taken from: theserverside(Mike Spille)
注:以上说明摘自:theserverside(Mike Spille)
jta="true", Transaction commit automatically.
jta="true",事务自动提交。
回答by jersey-city-ninja
I was wondering about this myself ("use JTA" option in a non-XA Datasource) so I tested several configurations. I have a distributed transaction connecting to two MySQL servers.
我自己也在想这个问题(非 XA 数据源中的“使用 JTA”选项),所以我测试了几种配置。我有一个分布式事务连接到两个 MySQL 服务器。
Here are my results. If I have:
这是我的结果。如果我有:
- Two non-XA datasources, both have JTA="true"
- 两个非 XA 数据源,都有 JTA="true"
Result: Error "Could not enlist in transaction on entering meta-aware object."
结果:错误“在输入元感知对象时无法在事务中登记。”
- Two non-XA datasources, with one JTA="true"
- 两个非 XA 数据源,其中一个 JTA="true"
Result: They won't participate in the distributed transaction. Each will commit separately.
结果:他们不会参与分布式事务。每个将单独提交。
- One XA and one non-XA with JTA="false",
- 一个 XA 和一个非 XA,其中 JTA="false",
Result: same as #2
结果:与#2相同
- One XA and one non-XA with JTA="true".
- 一个 XA 和一个非 XA,其中 JTA="true"。
Result: Works!
结果:有效!
From these, it looks like "use JTA" option indicates if it will participate in a distributed transaction if there's an XA datasource.
从这些来看,“使用 JTA”选项似乎表明如果有 XA 数据源,它是否会参与分布式事务。