2 Replies Latest reply on Oct 10, 2011 10:20 AM by Hubert Lyczek

    transactions - ejb 3 specification violated?

    Hubert Lyczek Newbie

      Hello all,


      Java: 1.6.0_23

      AS: 6.0.0, 6.1.0



      I've spotted recently that Jboss AS does not follow ejb 3 specification requirements for transactions.

      Let's look at simple code below:



      public class TransactionBean implements TransactionLocal, TransactionRemote{
       private SessionContext sCtx;
       private Logger logger = Logger.getLogger(TransactionBean.class);
       public void transactionA() {
        logger.info("------------transaction A begin-------------------");
        logger.info("rollback: " + sCtx.getRollbackOnly());
        logger.info("rollback: " + sCtx.getRollbackOnly());
        logger.info("------------transaction A end-------------------");
       public void transactionB() {
        logger.info("------------transaction B begin-------------------");
        }catch(IllegalStateException ise){
         logger.info("IllegalStateException has been caught");
        logger.info("------------transaction B end-------------------");


      We have 2 methods:

      - transactionA

      - transactionB


      If we call transactionB method we will see output like this:


      ------------transaction B begin-------------------
      IllegalStateException has been caught
      ------------transaction B end-------------------


      Everything is ok. There is no transaction, so exception is thrown. Good. Let's call method transactionA.

      The output is like below:



      ------------transaction A begin-------------------
      rollback: false
      ------------transaction B begin-------------------
      ------------transaction B end-------------------
      rollback: true
      ------------transaction A end-------------------


      Hey, that is something different from expected.

      1. The method with transaction attribute NEVER is called from method associated with a transaction. Exception should be thrown (RemoteException or EJBException).

      2. There is a transaction context associated with methodB. So when method setRollbackOnly is called exception IllegalStateException in not thrown. But according to the specification method transactionB should be invoked without a transaction context.

      3. The transaction context associated with method transactionB is the same as transaction context associated with method transactionA. So when method setRollbackOnly is called inside method transactionB, the transaction that has been begun in method A is set for rollback. That is wrong.


      Simply a transaction context associated with method transactionA is propagated to method transactionB.


      This is the only one example. There is more.


      Could anyone explain that?

      For me it looks like ejb 3 specification violation.

      Am I wrong?



      thanks in advance