本文介绍了“jta-datasource”之间的差异。和“资源本地的“数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

术语jta-datasource和resource-local datasource对我来说有点模糊。我正在放下我理解(或假设)的内容,我想让你说出我对错的地方。

The terms "jta-datasource" and "resource-local datasource" are a little vague to me. I'm putting down what I am understanding ( or assuming ) and I'd like you to say where I'm right / wrong.


  • 同一个数据库可以称为jta-datasource或资源本地数据源

  • 如果提到jta-datasource,则bean /其他类可以使用JTA。因此,UserTransaction接口

  • 无法使用 /

  • 如果提到资源本地数据源,则事务不能识别JTA。代码可以使用EntityTransaction接口但不能使用UserTransaction接口

  • The same database can be referred to as a jta-datasource or as a resource local datasource
  • If mentioned as jta-datasource, then the beans / other classes can use JTA. Hence, UserTransaction interface
  • Cannot use CMT / BMT if the datasource is resource local
  • If mentioned as resource local datasource, transactions are not JTA aware. Code can use EntityTransaction interface but not UserTransaction interface

谢谢!

推荐答案

我猜你实际上是指 jta-datasource 非jta-datasource 元素。简而言之:

I guess you actually refer to the jta-datasource and non-jta-datasource elements. In short:


  • 如果持久性单元的事务类型是 JTA jta-datasource 元素用于声明将用于获取连接的JTA数据源的JNDI名称。这是常见的情况。

  • 如果持久性单元的事务类型是 resource-local ,则非jta数据 - source 应该用于声明非JTA数据源的JNDI名称。

  • if the transaction type of the persistence unit is JTA, the jta-datasource element is used to declare the JNDI name of the JTA data source that will be used to obtain connections. This is the common case.
  • if the transaction type of the persistence unit is resource-local, the non-jta-data-source should be used to declare the JNDI name of a non-JTA data source.

这是正确的。我刚才没有提到,但有些提供商甚至允许声明 jta-datasource a 非-jta-datasource 并使用后者通过非JTA连接优化读取(即不会与正在进行的JTA事务关联)。

This is correct. And I didn't mention that just above but some providers even allow to declare both a jta-datasource and a non-jta-datasource and use the later for optimized reading through non-JTA connections (i.e. that won't be associated to an ongoing JTA transaction).

第一部分是正确的,最后一部分不完全。从EJB 3.0规范, 13.3.4企业Bean使用容器管理的事务划分部分:

The first part is correct, the last part not entirely. From the EJB 3.0 spec, section 13.3.4 Enterprise Beans Using Container-Managed Transaction Demarcation:

并且 16.12 UserTransaction接口部分:

换句话说,CMT企业bean无法使用 UserTransaction 界面。

In other words, the UserTransaction interface is not available to CMT enterprise beans.

这里的措辞有点令人困惑,但我会说这不是严格正确的。从JPA 1.0规范,§5.5控制交易部分:

The wording is a bit confusing here but I'd say that this not strictly correct. From the JPA 1.0 specification, section § 5.5 Controlling Transactions:

...

两个JTA实体经理和Java EE Web容器和EJB容器中需要支持资源本地实体管理器。在EJB环境中,通常使用JTA实体管理器。

Both JTA entity managers and resource-local entity managers are required to be supported in Java EE web containers and EJB containers. Within an EJB environment, a JTA entity manager is typically used.

部分6.2.1.2 transaction-type

因此,您可以使用应用程序管理实体管理器,它可以是资源本地实体经理(在这种情况下,你必须注入一个 EntityManagerFactory 来从中获取EM)并且它不会成为JTA事务的一部分。请参阅。

So you CAN use an application managed entity manager which can be a resource-local entity manager (you must inject an EntityManagerFactory to get the EM from it in that case) and it won't be part of a JTA transaction. See this (very interesting) discussion.

同样,措辞有点令人困惑但我我说这是正确的。

Again, the wording is a bit confusing but I'd say that this is correct.

这篇关于“jta-datasource”之间的差异。和“资源本地的“数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:40