将IBM StartupBean EJB1.1迁移到@Startup EJB3.1

时间:2018-10-24 20:33:38

标签: java websphere ejb-3.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)。然后,它应该提交该事务,以保留该实体并调用查找程序,该查找程序在数据库中搜索该记录。看起来像:

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中,创建并存储了实体。现在不是。我很遗憾在申请开始时并没有某种程度的支持交易。是这样吗?还是有什么方法可以强制使用事务或某种解决方法?谢谢。

0 个答案:

没有答案
相关问题