更改应用程序使其具有 WebSphere“特定版本”的 setRollbackOnly 行为

使用此任务以允许 EJB 3.0 之后版本的应用程序展示 EJB 3.0 之前版本的行为,并允许 EJB 3.0 之前版本的应用程序展示 EJB 3.0 之后版本的行为。本任务中提供此处理行为的步骤基于非常具体的处理方案,“关于此任务”部分中进行了说明。

关于此任务

处理方案:此任务的基础是以下处理方案。

系统会调用 EJB 方法以启动全局事务。在执行此方法时,系统会调用另一 EJB 方法以继续在同一事务内运行。在执行此方法时,系统会调用 setRollbackOnly() 方法。遇到此方案时的 EJB 容器行为按 EJB 规范执行。但是,在 WebSphere® Application Server 中,需要更改此行为以获取 EJB 3.0 支持。

JSR 220: Enterprise JavaBeans™,Version 3.0 EJB Core Contracts and Requirements 文档的 13.6.2.8 部分及先前版本的 EJB 规范指示:

“If the container initiated the transaction immediately before dispatching the business method to the instance (as opposed to the transaction being inherited from the caller), the container must note that the instance has invoked the setRollbackOnly method. When the business method invocation completes, the container must roll back rather than commit the transaction. If the business method has returned normally or with an application exception, the container must pass the method result or the application exception to the client after the container performed the rollback.” 而 14.3.11 部分中指示:“However, the container should not throw the javax.ejb.EJBException or java.rmi.RemoteException or if the container performs a transaction rollback because the instance has invoked the setRollbackOnly method on its EJBContext object. In this case, the container must rollback the transaction and pass the business method result or the application exception thrown by the business method to the client.”

从历史上看,WebSphere Application Server 已解释规范的以上部分以指示仅当事务在开始该事务的方法内标记为 RollbackOnly 时,才应应用 setRollbackOnly 行为。但是,对应 EJB 3.0 规范的 Compatibility Test Suite 要求标记为 RollbackOnly 的事务展示以上 setRollbackOnly 行为,不管该事务是否在开始该事务的方法内或从原始 EJB 方法调用的同一事务中的另一方法内标记为 RollbackOnly。

为说明此要求,请考虑以下示例:
  • 应用程序对带有容器管理的事务支持 (TX_REQUIRED) 的 EJB A 调用方法 art
  • 容器开始事务并调用该方法。
  • 方法 A.art() 对带有容器管理的事务支持 (TX_REQUIRED) 的 EJB B 调用方法 bob
  • B.bob() 内,系统对事务调用 setRollbackOnly 方法并完成。

EJB 3.0 之前的行为:因为未使用 B.bob() 方法启动事务,所以系统会向 A.art() 抛出 TranactionRolledbackException 并最终发送至客户机应用程序。

EJB 3.0 及之后版本中的行为:方法 B.bob() 正常返回至方法 A.art()。方法 A.art() 对事务执行回滚并将结果返回至客户机而不向客户机应用程序抛出异常(如 EJB 规范所述)。

因为对从先前版本迁移至 EJB 3.0 或之后版本的应用程序而言,此处理的行为发生了更改,所以系统提供了以下 JVM 系统属性来更改此行为以符合您的要求:
  • com.ibm.websphere.ejbcontainer.limitSetRollbackOnlyBehaviorToInstanceFor:此属性允许用户指定应用程序名称,在这些应用程序中,他们希望 EJB 3.0 模块中的 EJB 演示此部分中描述的 EJB 3.0 之前版本的 setRollbackOnly 行为。
  • com.ibm.websphere.ejbcontainer.extendSetRollbackOnlyBehaviorBeyondInstanceFor:此属性允许用户指定应用程序名称,在这些应用程序中,他们希望 pre-EJB 3.0 模块中的 EJB 演示此部分中描述的 EJB 3.0 版本的 setRollbackOnly 行为。
这些属性的值设置为需要演示预期行为的应用程序名称 (appName1:appName2:appName3)。

过程

  1. 打开管理控制台。
  2. 选择服务器
  3. 选择服务器类型
  4. 选择 WebSphere 应用程序服务器
  5. 选择要配置的服务器。
  6. 在“服务器基础结构”下,选择 Java 和进程管理 > 进程定义
  7. 在“其他属性”下,选择 Java 虚拟机 > 定制属性 > 新建
  8. 名称输入字段中,输入 JVM 系统属性。

    com.ibm.websphere.ejbcontainer.limitSetRollbackOnlyBehaviorToInstanceFor

    com.ibm.websphere.ejbcontainer.extendSetRollbackOnlyBehaviorBeyondInstanceFor

  9. 输入字段中,输入 (appName1:appName2:appName3....). 应该应用行为的应用程序的名称。
  10. 选择确定
  11. 保存配置。
  12. 重新启动服务器。

指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tejb_version_specific
文件名:tejb_version_specific.html