2 Replies Latest reply on May 26, 2011 6:41 AM by paul_m

    getRollbackOnly() behaving strangely with inheritance in JBoss 6

    paul_m Newbie

      The following issue shows up with jboss-6.0.0.Final but works as I'd expect with jboss-5.1.0.GA.  Also, although I've not tested this extensively, I've only been aware of this problem when using EJB3 annotations.

       

      The EJB spec' seems pretty clear that EJBContext.getRollbackOnly() should throw java.lang.IllegalStateException if a bean's TransactionAttribute is 'NOT_SUPPORTED'.

       

      I have a base class with a method that uses getRollbackOnly().  In this example hasTxn() simply uses getRollbackOnly() to determine whether the method is called in the context of a container-managed transaction:

       

      {code}

      import javax.annotation.Resource;

      import javax.ejb.SessionContext;

       

      public class TxnTestSSBBase

      {

          @Resource SessionContext ctx;

       

          public boolean hasTxn()

          {

              try

              {

                  ctx.getRollbackOnly();

                  return true;

              }

              catch (IllegalStateException e)

              {

                  return false;

              }

          }

      }

      {code}

       

      I then have an EJB (in this example a Stateless Session Bean) that extends the base class and implements a remote interface with the hasTxn() method.  Note that the bean's TransactionAttribute is NOT_SUPPORTED, and that the hasTxn() method in the sub-class (TxnTestSSB) is currently commented out so the super-class's implementation is called directly.

       

      {code}

      import javax.ejb.Stateless;

      import javax.ejb.TransactionAttribute;

      import javax.ejb.TransactionAttributeType;

      import javax.ejb.TransactionManagement;

      import javax.ejb.TransactionManagementType;

       

      @TransactionManagement(TransactionManagementType.CONTAINER)

      @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

      @Stateless

      public class TxnTestSSB extends TxnTestSSBBase implements TxnTestSSBRemote

      {

      /*

          public boolean hasTxn()

          {

              return super.hasTxn();

          }

      */

      }

      {code}

       

      Deployed in JBoss 5.1 hasTxn() returns 'false' which is what I'd expect.  But if I deploy it in JBoss 6.0 hasTxn() returns 'true' - i.e. getRollbackOnly() completes without throwing an IllegalStateException in spite of the NOT_SUPPORTED TransactionAttribute.

       

      Interestingly, if I implement hasTxn() in TxnTestSSB, even if the implementation simply calls the super class (i.e. uncomment the commented-out code shown above), it correctly returns 'false' in JBoss 6.0.

       

      Am I missing something here?  Is this a known bug?  I've searched around a little, but maybe the underlying issue is broader than getRollbackOnly()/setRollbackOnly() and so I've missed it, not knowing quite what to search on?

       

      Thanks for any help anyone can provide,

       

      Paul.