1 Reply Latest reply on Mar 25, 2014 8:26 AM by Andy Taylor

    RuntimeException subclass annotated with @ApplicationException(rollback=false) still rolls back if

    John Francis Newbie

      I am using Jboss As 7.1.1.Final with Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)  under Windows 7

       

      I have a vanilla Message Driven Bean;

       

      @MessageDriven(name = "QTestAppExceptionMDB", activationConfig = {

        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),

        @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/streamedAppErrorQ"),

        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })

      @TransactionAttribute(TransactionAttributeType.REQUIRED)

      public class QTestAppExceptionMDB implements MessageListener {

       

        private static int beans = 0;

        private int count = 0;

        private String id;

        {

        DateTime now = DateTime.now();

        DateTimeFormatter fmt = DateTimeFormat.forPattern("k:m:s.SSS");

        id = "MDB (AppExceptioning) ID=" + ++beans + ", " + now.toString(fmt);

        }

       

       

        public QTestAppExceptionMDB() throws JAXBException {

        }

       

        public void onMessage(Message message) {

        ++count;

        System.err.println(id + ": count is " + count);

        System.err.flush();

        forwardMessage(message);

        throw new MyNonRollbackRuntimeException("This is a BL error: ");

        }

       

       

        private void forwardMessage(Message message) {

        String destinationName = "queue/streamed";

        Context ic = null;

        ConnectionFactory cf = null;

        Connection connection = null;

       

       

        try {

        ic = new InitialContext();

       

       

        cf = (ConnectionFactory) ic.lookup("/JmsXA");

        Queue queue = (Queue) ic.lookup(destinationName);

       

       

        connection = cf.createConnection();

        Session session = connection.createSession(false,

        Session.AUTO_ACKNOWLEDGE);

        MessageProducer publisher = session.createProducer(queue);

       

       

        connection.start();

       

       

        publisher.send(message);

        } catch (Exception exc) {

        exc.printStackTrace();

        } finally {

       

       

        if (connection != null) {

        try {

        connection.close();

        } catch (JMSException e) {

        e.printStackTrace();

        }

        }

        }

        }

      }

       

      MyNonRollbackRuntimeException is a RuntimeException which is marked as an Application Exception,

      with rollback=false;


      @SuppressWarnings("serial")

      @ApplicationException(rollback=false)

      public class MyNonRollbackRuntimeException extends RuntimeException {

       

       

        public MyNonRollbackRuntimeException(String arg0) {

        super(arg0);

        }

      }

       

      When I run the example the message forwarded by forwardMessage is not seen by the 'downstream' message listener.

      If I comment out the throw of MyNonRollbackRuntimeException, it is.

      So I assume despite the fact that my RuntimeException is marked as rollback=false, the transaction is being rolledback.

      HornetMQ goes into its normal resubmission protocol, and I see the message being resubmitted as if it had been rolledback.

      There is a difference between the behaviour of MyNonRollbackRuntimeException and a normal RuntimeException which is that the MDB instance is not discarded if the MyNonRollbackRuntimeException is thrown.

       

      Looking at;

       

      http://download.oracle.com/otn-pub/jcp/ejb-3_2-fr-spec/ejb-3_2-core-fr-spec.pdf?AuthParam=1395747241_4b65d8cc04f2407e66b309b4860a3321

       

      p 213 Table 12 in the section 9.3.4 Exceptions from Message-Driven Bean Message Listener Methods, it might appear that I should expect the transaction to commit, but it is not clear.

       

      Do the HornetMQ maintainers think this is a bug, or is it just badly defined by the specs (or is there another spec I missed) and therefore up to the implementers?

       

       

      Thanks

       

      Moved to AS forum  https://community.jboss.org/thread/238424