Ger*_*llo 68 java jpa jta persistence.xml java-ee
在persistence.xml JPA配置文件中,您可以使用如下行:
<persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type="JTA">
或有时:
<persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type=”RESOURCE_LOCAL”>
我的问题是:
transaction-type="JTA"和之间有什么区别transaction-type=”RESOURCE_LOCAL”?
我还注意到一些缺少事务类型的persistence.xml文件.这是对的吗?
Jir*_*ser 113
默认为JavaEE环境中的JTA和JavaSE环境中的RESOURCE_LOCAL.
随着<persistence-unit transaction-type="RESOURCE_LOCAL">你负责EntityManager(PersistenceContext/Cache)创建和跟踪
EntityManagerFactory来得到一个EntityManagerEntityManager实例是一个PersistenceContext/Cache
An EntityManagerFactory只能通过@PersistenceUnit注释注入(不是@PersistenceContext)@PersistenceContext用于引用类型的单位RESOURCE_LOCALEntityTransactionAPI开始/提交每次调用您的EntityMangerentityManagerFactory.createEntityManager()两次导致两个单独的EntityManager实例,因此两个单独的实例PersistenceContexts/Caches.EntityManager正在使用的实例几乎绝不是一个好主意(除非你已经破坏了第一个实例,否则不要创建第二个实例)随着<persistence-unit transaction-type="JTA">容器将do EntityManager(PersistenceContext/Cache)创建和跟踪.
EntityManagerFactory来得到一个EntityManagerEntityManager容器提供的产品EntityManager可以通过被注入@PersistenceContext注解只有(未@PersistenceUnit)@PersistenceUnit用于引用JTA类型的单位EntityManager由给定的容器是将参考PersistenceContext/Cache与JTA事务相关联.EntityManager则不能使用,因为没有PersistenceContext/Cache.EntityManager在同一事务中引用同一单元的每个人都将自动引用相同的单元PersistenceContext/CachePersistenceContext/Cache刷新和JTA清除提交时间| 归档时间: | 
 | 
| 查看次数: | 56389 次 | 
| 最近记录: |