本文介绍了Transaction-scoped Persistence上下文和Extended Persistence上下文之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Transaction-scoped Persistence context和Extended Persistence context之间的区别是什么?

What is the difference between Transaction-scoped Persistence context and Extended Persistence context ??

推荐答案

差异在 Enterprise JavaBeans 3.0规范:

The difference is clearly explained in the JSR-220 Enterprise JavaBeans 3.0 specification:

容器管理的持久性
上下文可以被定义为具有范围为单个
事务的
a生存期或跨越多个的延长生命周期
交易,
,具体取决于
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

当活动JTA的范围
中调用容器管理的实体管理器
$ sup; [36] 时,新的持久化上下文开始事务和
没有当前持久性
上下文已与
JTA事务关联。创建持久性
上下文,然后将
与JTA事务关联。

A new persistence context begins when the container-managed entity manager is invoked 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 注释或
persistence-context-ref声明的。部署
描述符元素。

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 的容器关闭c>
有状态会话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).

(。 ..)

这篇关于Transaction-scoped Persistence上下文和Extended Persistence上下文之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 21:49