“jta-datasource”之间的差异。和“资源本地的“数据源? [英] Difference between a "jta-datasource" and a " resource-local " datasource?

查看:111
本文介绍了“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接口

  • 无法使用如果数据源是本地资源,则CMT / BMT

  • 如果提到资源本地数据源,则事务不能识别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和resouce-local datasource对我来说有点模糊。

The terms "jta-datasource" and "resouce-local datasource" are a little vague to me.

我猜你实际上是指 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或资源本地数据源

这是正确的。我刚才没有提到,但有些提供商甚至允许声明 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).



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

第一部分是正确的,最后一部分不完全。从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:


企业bean的业务方法[...]不得试图获取或使用 javax.transaction.UserTransaction 接口。

并且 16.12 UserTransaction接口部分:


容器不能生成 UserTransaction 可供不允许使用此接口的企业bean使用的接口。

The container must not make the UserTransaction interface available to the enterprise beans that are not allowed to use this interface.

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

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



  • 如果数据源是本地资源,则无法使用CMT / BMT

这里的措辞有点令人困惑,但我会说这不是严格正确的。从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实体经理或资源本地实体经理。

An application-managed entity manager may be either a JTA entity manager or a resource-local entity manager.

...

两个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


transaction-type 属性用于指定实体管理器是否提供由实体管理器工厂为持久性单元必须是JTA实体管理器或资源本地实体管理器。此元素的值为 JTA RESOURCE_LOCAL 。事务类型的JTA假定将提供JTA数据源 - 由 jta-data-source 元素指定或由容器提供。通常,在Java EE环境中, RESOURCE_LOCAL 事务类型假定将提供非JTA数据源。在Java EE环境中,如果未指定此元素,则默认值为JTA。

The transaction-type attribute is used to specify whether the entity managers provided by the entity manager factory for the persistence unit must be JTA entity managers or resource-local entity managers. The value of this element is JTA or RESOURCE_LOCAL. A transaction-type of JTA assumes that a JTA data source will be provided — either as specified by the jta-data-source element or provided by the container. In general, in Java EE environments, a transaction-type of RESOURCE_LOCAL assumes that a non-JTA datasource will be provided. In a Java EE environment, if this element is not specified, the default is JTA.

因此,您可以使用应用程序管理实体管理器,它可以是资源本地实体经理(在这种情况下,你必须注入一个 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.



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

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

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

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

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