2

是否可以从有状态 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: Illegal Reentrant Access : Attempt to make a loopback call on method 'public void com.test.MyService .save() 用于有状态会话 bean MyService

SFSB 不支持内部调用吗?

I'm running Glassfish 3.1.1.

4

1 回答 1

2

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

于 2011-11-04T12:01:51.033 回答