首页 > 解决方案 > 将 IBM StartupBean EJB1.1 迁移到 @Startup EJB3.1

问题描述

我们正在迁移以前使用 IBM 接口的 1.1 StartUp bean:

<session id="StartUp">
    <ejb-name>StartUp</ejb-name>
    <home>com.ibm.websphere.startupservice.AppStartUpHome</home>
    <remote>com.ibm.websphere.startupservice.AppStartUp</remote>
    <ejb-class>org.bean.StartUpBean</ejb-class>
    <session-type>Stateful</session-type>
    <transaction-type>Container</transaction-type>
</session>

符合 EJB 3.1 标准。到目前为止,我们在没有使用 IBM 属性实现的情况下为 bean 编写代码:

@Startup
@Singleton
public class StartUpBean{

@PostConstruct
    public void start() {
       ...
       helper.runHelper(); // in new class
     }
   }

起初我们的部署顺序有问题,因为 StartupBean 是在模块之后立即启动的。我们在 application.xml 中使用不同的顺序解决了这个问题。然而,一个问题仍然存在。

在从这个 bean 的 start 方法调用的辅助方法中,我们有一些代码使用 JNDI 名称查找无状态 1.1 bean。该 bean 创建新的实体 bean (1.1),在新事务中调用方法 create(使用 xml 描述符中的 reguires_new)。然后它应该提交该事务以持久化该实体并调用在数据库中搜索该记录的 finder。看起来像:

void runHelper(){
   ... 
   oldRemote = Server.lookup(OldBean.JNDI, OldBean.class);
   oldBean.prepareApp(); //prepareApp has requires new transaction attribute
   findThatNewEntity(key); // FinderException (not in database)
}

在旧的无状态 bean 1.1

void prepareApp(){
 entityHome = Server.lookup(JNDI_NAME, Data.class);
 entityHome.create(key, value, value2);
}

我 100% 确定,在使用 IBM 接口的以前版本的 StartUp bean 中,实体被创建和存储。现在不是。我担心在应用程序启动时不支持事务。是这样吗?或者有什么方法可以强制使用事务或某种解决方法?谢谢你。

标签: javawebsphereejb-3.1

解决方案


推荐阅读