Transactions 全局事务websphere 8.5.5.11 ejb

Transactions 全局事务websphere 8.5.5.11 ejb,transactions,websphere,commit,ejb-3.0,ejb-3.1,Transactions,Websphere,Commit,Ejb 3.0,Ejb 3.1,我有一个界面: 公共接口LogBookService扩展了EntityService{ 无效的writeLogenTransaction(LogBookEntity日志); } 及其实施: @无状态 @TransactionManagement(TransactionManagementType.CONTAINER) @TransactionAttribute(TransactionAttributeType.REQUIRED) 公共类LogBookServiceImpl实现LogBookSe

我有一个界面:

公共接口LogBookService扩展了EntityService{
无效的writeLogenTransaction(LogBookEntity日志);
}
及其实施:

@无状态
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
公共类LogBookServiceImpl实现LogBookService{
@TransactionAttribute(TransactionAttributeType.REQUIRES\u NEW)
公共无效书面记录交易(日志实体日志){
最终列表参数=新的ArrayList();
新建getRepository().merge(实体);
}
}
第三种服务:

@无状态
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
公共类GalaxyServiceImpl实现GalaxyService{
@资源
非公开会话上下文会话上下文;
公开无效测试(){
用于(LogBookEntity日志:LogBookEntities){
getBusinessObject(LogBookService.class).writeLogonTransaction(log);
}
}
}
例如,当我通过web服务调用GalaxyServiceImpl时,出现以下错误:

SystemErr R java.lang.IllegalStateException: Requested business interface not found : LogBookService
SystemErr R     at com.ibm.ejs.container.SessionBeanO.getBusinessObject(SessionBeanO.java:677)

您能告诉我为什么吗?

SessionContexts是特定于每个bean实例的。由于您在GalaxyServiceImpl bean中进行依赖项注入,因此您获取的是该bean的SessionContext,而不是LogBookServiceImpl bean。GalaxyServiceImpl没有实现LogBookService,所以这就是为什么它抱怨您找不到它的业务接口


相反,您可以使用@EJB注入LogBookServiceImpl bean,或者执行JNDI查找来查找该bean。您可以使用注入的SessionContext作为JNDI查找的上下文或获取初始上下文。

在使用SessionContext之前,我尝试了以下方法:@Inject private LogBookService LogBookService;对于(LogBookEntity log:LogBookEntities){logBookService.writelognettransaction(log);}但它不起作用,我假设调用方法'writelognettransaction()'将启动一个新的事务上下文。但是当我测试这段代码时,我看到“WriteLogenTransaction(log)”方法从未在单独的事务中运行过–EJB容器将忽略TransactionAttribute类型“REQUIRES_NEW”!嗯,看起来它应该可以工作了,而且在没有跟踪的情况下调试有点困难。您在ibm-ejb-jar.xml中有任何内容和/或安装了元数据完整设置为true的应用程序吗?没有ibm-ejb-jar.xml或metadata complete=true,我想我遇到了与此相同的问题:,正如您所说,我在GalaxyService inetrface中添加了writeLogeneTransaction,并在GalaxyServiceImpl中实现,它是有效的。