事务范围的持久化上下文和扩展持久化上下文有什么区别? [英] What is the difference between Transaction-scoped Persistence context and Extended Persistence context?
问题描述
事务范围的持久化上下文和扩展持久化上下文有什么区别?
What is the difference between Transaction-scoped Persistence context and Extended Persistence context?
推荐答案
区别在 JSR-220 Enterprise JavaBeans 3.0 规范:
The difference is clearly explained in the JSR-220 Enterprise JavaBeans 3.0 specification:
(...)
一个容器管理的持久化上下文可以定义为具有范围限定为单个的生命周期交易或延长生命周期跨越多个交易,取决于PersistenceContextType
即当它的 EntityManager
是创建.本规范是指像这样的持久化上下文事务范围的持久性上下文和扩展持久性上下文.
A container-managed persistence
context may be defined to have either
a lifetime that is scoped to a single
transaction or an extended lifetime
that spans multiple transactions,
depending on the
PersistenceContextType
that is
specified when its EntityManager
is
created. This specification refers to
such persistence contexts as
transaction-scoped persistence contexts and extended persistence
contexts respectively.
(...)
该应用程序可能会获得一个容器管理的实体管理器事务范围的持久化上下文绑定到 JTA 事务在 JNDI 中注入或直接查找命名空间.持久化上下文实体管理器的类型是默认或定义为PersistenceContextType.TRANSACTION
.
The application may obtain a
container-managed entity manager with
transaction-scoped persistence context
bound to the JTA transaction by
injection or direct lookup in the JNDI
namespace. The persistence context
type for the entity manager is
defaulted or defined as
PersistenceContextType.TRANSACTION
.
一个新的持久化上下文开始于容器管理的实体管理器在作用域内调用[36]一个活跃的 JTA 事务,和目前没有持久性上下文已经与JTA 事务.坚持创建上下文然后关联与 JTA 事务.
A new persistence context begins when the container-managed entity manager is invoked[36] in the scope of an active JTA transaction, and there is no current persistence context already associated with the JTA transaction. The persistence context is created and then associated with the JTA transaction.
持久化上下文在关联的 JTA 事务提交或回滚,所有实体由 EntityManager 管理成为分离.
The persistence context ends when the associated JTA transaction commits or rolls back, and all entities that were managed by the EntityManager become detached.
如果实体管理器被调用在交易范围之外,从数据库加载的任何实体将立即变得分离方法调用结束.
If the entity manager is invoked outside the scope of a transaction, any entities loaded from the database will immediately become detached at the end of the method call.
一个容器管理的扩展持久化上下文只能是范围内发起的有状态会话 bean.它存在于有状态的点声明一个会话 bean对实体管理器的依赖输入 PersistenceContextType.EXTENDED
被创建,并且被称为绑定到有状态会话 bean.这对扩展持久性的依赖上下文是通过以下方式声明的PersistenceContext
注释或持久化上下文引用部署描述符元素.
A container-managed extended
persistence context can only be
initiated within the scope of a
stateful session bean. It exists from
the point at which the stateful
session bean that declares a
dependency on an entity manager of
type PersistenceContextType.EXTENDED
is created, and is said to be bound to
the stateful session bean. The
dependency on the extended persistence
context is declared by means of the
PersistenceContext
annotation or
persistence-context-ref deployment
descriptor element.
持久化上下文被关闭@Remove
时的容器有状态会话 bean 的方法完成(或有状态的会话否则会销毁 bean 实例).
The persistence context is closed by
the container when the @Remove
method of the stateful session bean
completes (or the stateful session
bean instance is otherwise destroyed).
(...)
这篇关于事务范围的持久化上下文和扩展持久化上下文有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!