“jta-datasource"和“jta-datasource"之间的区别和一个“本地资源数据源? [英] Difference between a "jta-datasource" and a " resource-local " datasource?

查看:65
本文介绍了“jta-datasource"和“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,那么beans/其他类可以使用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"和resource-local datasource"对我来说有点含糊.

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

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

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

  • 如果持久化单元的事务类型是JTA,则jta-datasource元素用于声明JTA数据源的JNDI名称,该JTA数据源将用于获取连接.这是常见的情况.
  • 如果持久化单元的事务类型是resource-local,则应该使用non-jta-data-source来声明一个非JTA 数据源.
  • 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 non-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,那么beans/其他类可以使用JTA.因此,UserTransaction 接口.

第一部分是正确的,最后一部分不完全正确.来自 EJB 3.0 规范的 13.3.4 Enterprise Beans Using Container-Managed Transaction Demarcation 部分:

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 接口.

The enterprise bean’s business methods [...] must not attempt to obtain or use the javax.transaction.UserTransaction interface.

以及16.12 UserTransaction Interface部分:

容器不得使UserTransaction 接口可用于不允许使用该接口的企业bean.

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

换句话说,UserTransaction 接口对 CMT 企业 bean 不可用.

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 属性用于指定实体管理器工厂为持久化单元提供的实体管理器必须是 JTA 实体管理器还是资源本地实体管理器.该元素的值为JTARESOURCE_LOCAL.JTA 的事务类型假定将提供 JTA 数据源——要么由 jta-data-source 元素指定,要么由容器提供.通常,在 Java EE 环境中,RESOURCE_LOCALtransaction-type 假定将提供非 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才能得到在这种情况下,它不会成为 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"和“jta-datasource"之间的区别和一个“本地资源数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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