【问题标题】:global transaction websphere 8.5.5.11 ejb全局事务 websphere 8.5.5.11 ejb
【发布时间】:2020-04-10 02:02:55
【问题描述】:

我有一个界面:

public interface LogBookService extends EntityService<LogBookEntity, Long> {
    void writelogNewTransaction(LogBookEntity log);
}

及其实现:

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class LogBookServiceImpl implements LogBookService {
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void writelogNewTransaction(logBookEntity logbook) {
        final List<String> params = new ArrayList<String>();
        new getRepository().merge(entity);
    }
}

第三个服务:

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class GalaxyServiceImpl implements GalaxyService {
    @Resource
    private SessionContext  sessionContext ;
    public void test() {
        for (LogBookEntity log : LogBookEntities) {
            sessionContext.getBusinessObject(LogBookService.class).writelogNewTransaction(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)

你能告诉我为什么吗?

【问题讨论】:

    标签: transactions websphere commit ejb-3.0 ejb-3.1


    【解决方案1】:

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

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

    【讨论】:

    • 在使用 SessionContext 之前,我试过这个:@Inject private LogBookService logBookService; for (LogBookEntity log : LogBookEntities) {logBookService.writelogNewTransaction(log);} 但它不起作用,我假设方法“writelogNewTransaction()”的调用将启动一个新的事务上下文。但是当我测试这段代码时,我看到方法‘writelogNewTransaction(log)’从未在单独的事务中运行——EJB容器将忽略transactionAttributeType‘REQUIRES_NEW’!
    • 嗯,看起来它应该可以工作了,而且在没有痕迹的情况下调试有点困难。您是否在 ibm-ejb-jar.xml 中有任何内容和/或安装了元数据完整设置为 true 的应用程序?
    • 没有 ibm-ejb-jar.xml 也没有 metadata-complete=true ,我想我有同样的问题:blog.imixs.org/2014/02/20/…,正如你所说,我在 GalaxyService 中添加了 writelogNewTransaction inetrface,以及 GalaxyServiceImpl 中的实现,它可以工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-21
    • 2014-04-08
    相关资源
    最近更新 更多