Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top