[英]persistence.xml different transaction-type attributes
In the persistence.xml JPA configuration file, you can have a line like:在persistence.xml JPA 配置文件中,你可以有这样一行:
<persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type="JTA">
or sometimes:或有时:
<persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type=”RESOURCE_LOCAL”>
My question is:我的问题是:
What is the difference between transaction-type="JTA"
and transaction-type=”RESOURCE_LOCAL”
? transaction-type="JTA"
和transaction-type=”RESOURCE_LOCAL”
什么区别?
I also noticed some persistence.xml files with the transaction-type missing.我还注意到一些缺少事务类型的 persistence.xml 文件。 Is it correct?
这是正确的吗?
Default to JTA in a JavaEE environment and to RESOURCE_LOCAL in a JavaSE environment.在 JavaEE 环境中默认为JTA ,在 JavaSE 环境中默认为RESOURCE_LOCAL 。
With <persistence-unit transaction-type="RESOURCE_LOCAL">
you are responsible for EntityManager
( PersistenceContext/Cache
) creating and tracking使用
<persistence-unit transaction-type="RESOURCE_LOCAL">
您负责EntityManager
( PersistenceContext/Cache
) 创建和跟踪
EntityManagerFactory
to get an EntityManager
EntityManagerFactory
来获取EntityManager
EntityManager
instance is a PersistenceContext/Cache
An EntityManagerFactory
can be injected via the @PersistenceUnit
annotation only (not @PersistenceContext
)EntityManager
实例是PersistenceContext/Cache
EntityManagerFactory
只能通过@PersistenceUnit
注释注入(不是@PersistenceContext
)@PersistenceContext
to refer to a unit of type RESOURCE_LOCAL
@PersistenceContext
来引用RESOURCE_LOCAL
类型的单元EntityTransaction
API to begin/commit around every call to your EntityManger
EntityTransaction
API 来开始/提交对EntityManger
每次调用entityManagerFactory.createEntityManager()
twice results in two separate EntityManager
instances and therefor two separate PersistenceContexts/Caches
.entityManagerFactory.createEntityManager()
两次会导致两个单独的EntityManager
实例,因此导致两个单独的PersistenceContexts/Caches
。EntityManager
in use (don't create a second one unless you've destroyed the first)EntityManager
实例几乎从来都不是一个好主意(不要创建第二个实例,除非您已经销毁了第一个实例) With <persistence-unit transaction-type="JTA">
the container will do EntityManager
( PersistenceContext/Cache
) creating and tracking.使用
<persistence-unit transaction-type="JTA">
容器将执行EntityManager
( PersistenceContext/Cache
) 创建和跟踪。
EntityManagerFactory
to get an EntityManager
EntityManagerFactory
来获取EntityManager
EntityManager
supplied by the containerEntityManager
EntityManager
can be injected via the @PersistenceContext
annotation only (not @PersistenceUnit
) EntityManager
只能通过@PersistenceContext
注释注入(不是@PersistenceUnit
)@PersistenceUnit
to refer to a unit of type JTA@PersistenceUnit
来引用 JTA 类型的单元EntityManager
given by the container is a reference to the PersistenceContext/Cache
associated with a JTA Transaction.EntityManager
是对与 JTA 事务关联的PersistenceContext/Cache
的引用。EntityManager
cannot be used because there is no PersistenceContext/Cache
.EntityManager
因为没有PersistenceContext/Cache
。EntityManager
reference to the same unit in the same transaction will automatically have a reference to the same PersistenceContext/Cache
EntityManager
引用的人都会自动拥有对同一PersistenceContext/Cache
的引用PersistenceContext/Cache
is flushed and cleared at JTA commit time PersistenceContext/Cache
在 JTA 提交时被刷新和清除
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.