在同一 SFSB 内调用事务方法

发布于 2024-12-13 20:32:11 字数 1133 浏览 1 评论 0原文

是否可以从有状态 EJB 本身调用事务方法?说得更清楚一点:

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Stateless
public class MyService {

    @Resource
    SessionContext ctx;

    public void myMethod()  {
        // do something...

        // invoke method from the same class

        // As expected - this doesn't work as it's a regular local-call, 
        // it's not aware of EJB nature of this call.
        save();

        // Doesn't work (although it worked with SLSB)
        ctx.getBusinessObject(MyService.class).save();
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void save() {
        // do something...
    }
}

现在我想要实现的是让用户调用myMethod();我想确保该方法是在没有 JTA 事务的情况下执行的。在此调用之后,我想调用 save();将在事务中运行的方法。

如果我使用 ctx.getBusinessObject(-) 方法,我会得到:

警告:EJB 调用期间发生系统异常 MyService 方法 public void com.test.MyService.save() javax.ejb.IllegalLoopbackException:非法重入访问:尝试 对方法“public void”进行环回调用 com.test.MyService.save() 用于有状态会话 bean MyService

SFSB 不支持内部调用吗?

我正在运行 Glassfish 3.1.1。

Is it possible to invoke a transactional method from within a Stateful EJB itself? To speak more clearly:

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Stateless
public class MyService {

    @Resource
    SessionContext ctx;

    public void myMethod()  {
        // do something...

        // invoke method from the same class

        // As expected - this doesn't work as it's a regular local-call, 
        // it's not aware of EJB nature of this call.
        save();

        // Doesn't work (although it worked with SLSB)
        ctx.getBusinessObject(MyService.class).save();
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void save() {
        // do something...
    }
}

Now what I want to achieve is to let the user call myMethod(); I want to be sure that this method is executed without the JTA transaction. After this call I want to invoke a save(); method which will be run within a transaction.

If I use the ctx.getBusinessObject(-) method I get:

WARNING: A system exception occurred during an invocation on EJB
MyService method public void com.test.MyService.save()
javax.ejb.IllegalLoopbackException: Illegal Reentrant Access : Attempt
to make a loopback call on method 'public void
com.test.MyService.save() for stateful session bean MyService

Are the inner calls not supported for SFSBs?

I'm running Glassfish 3.1.1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菩提树下叶撕阳。 2024-12-20 20:32:11

这可能是 Glassfish EJB 实现中的一个错误。它不仅仅发生在您调用具有不同事务属性的方法时,还会发生在对有状态会话 bean 的每次可重入调用时。

只需尝试将一个简单的测试方法放入有状态 bean 中,并通过业务对象代理调用它即可。你会得到同样的异常。

在 JBoss AS 7 上,允许对有状态 bean 进行重入调用。顺便说一句,不久前 OpenEJB 中也存在类似的错误:https://issues.apache。 org/jira/browse/OPENEJB-1099

It might be a bug in the Glassfish EJB implementation. It doesn't just happen when you call a method with a different transaction attribute, it happens with every reentrant call to a stateful session bean.

Just try putting a simple test method in your stateful bean and call it via the business object proxy. You'll get the same exception.

On JBoss AS 7, reentrant calls to stateful beans are allowed. Incidentally, a similar bug was present in OpenEJB some time ago: https://issues.apache.org/jira/browse/OPENEJB-1099

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文