Uploaded image for project: 'EJB 3.0'
  1. EJB 3.0
  2. EJBTHREE-2250

Incorrect getRollbackOnly() behaviour for non-transacted bean with inheritance in JBoss 6

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Major
    • None
    • depchain-1.0.0-alpha-43
    • ejb3
    • Hide

      Deploy TxnTestSSB bean (code below) into JBoss AS and run TxnTestSSBClient to invoke the bean.

      With jboss-5.1.0.GA the client correctly displays:
      hasTxn() returns: false
      With jboss-6.0.0.Final the client wrongly displays:
      hasTxn() returns: true

      Try adding a hasTxn() method to TxnTestSSB and have it call super.hasTxn(). The client now correctly displays:
      hasTxn() returns: false

      =====================
      TxnTestSSBRemote.java
      =====================

      import javax.ejb.Remote;

      @Remote
      public interface TxnTestSSBRemote
      {
      public boolean hasTxn();
      }

      ===============
      TxnTestSSB.java
      ===============

      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
      {
      }

      ===================
      TxnTestSSBBase.java
      ===================

      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; }

      }
      }

      =====================
      TxnTestSSBClient.java
      =====================

      import java.util.Properties;
      import javax.naming.Context;
      import javax.naming.InitialContext;

      public class TxnTestSSBClient
      {
      public static void main(String[] args) throws Exception

      { Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); props.put(Context.PROVIDER_URL,"jnp://localhost:1099"); props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces"); InitialContext ctx = new InitialContext(props); TxnTestSSBRemote remote = (TxnTestSSBRemote) ctx.lookup("TxnTestSSB/remote"); System.out.println("hasTxn() returns: " + remote.hasTxn()); }

      }

      Show
      Deploy TxnTestSSB bean (code below) into JBoss AS and run TxnTestSSBClient to invoke the bean. With jboss-5.1.0.GA the client correctly displays: hasTxn() returns: false With jboss-6.0.0.Final the client wrongly displays: hasTxn() returns: true Try adding a hasTxn() method to TxnTestSSB and have it call super.hasTxn(). The client now correctly displays: hasTxn() returns: false ===================== TxnTestSSBRemote.java ===================== import javax.ejb.Remote; @Remote public interface TxnTestSSBRemote { public boolean hasTxn(); } =============== TxnTestSSB.java =============== 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 { } =================== TxnTestSSBBase.java =================== 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; } } } ===================== TxnTestSSBClient.java ===================== import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; public class TxnTestSSBClient { public static void main(String[] args) throws Exception { Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); props.put(Context.PROVIDER_URL,"jnp://localhost:1099"); props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces"); InitialContext ctx = new InitialContext(props); TxnTestSSBRemote remote = (TxnTestSSBRemote) ctx.lookup("TxnTestSSB/remote"); System.out.println("hasTxn() returns: " + remote.hasTxn()); } }

    Description

      If a method in a bean's super-class uses EJBContext.getRollbackOnly() it fails to throw an IllegalStateException if the bean's TransactionAttribute is NOT_SUPPORTED (unless the bean itself overrides the method and explicitly calls the super-class). From the EJB spec' I'd expect getRollbackOnly() to throw java.lang.IllegalStateException in this case.

      This appears to be a regression in JBoss 6.0 (seen with jboss-6.0.0.Final). The code works as I'd expect with jboss-5.1.0.GA.

      Attachments

        Issue Links

          Activity

            People

              rhn-engineering-cdewolf Carlo de Wolf
              paul_m_jira Paul Meadows (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: