ctx.setRollbackOnly() should be called first?

Discussions

EJB design: ctx.setRollbackOnly() should be called first?

  1. ctx.setRollbackOnly() should be called first? (3 messages)

    Dear forum,

    In the book by Floyd, EJB Design Patterns, there is a great emphasis on making sure to execute "ctx.setRollbackOnly()" in an EJB exception caught clause before re-throwing an app exception.

    Is this strategy applicable to Container Managed Transaction?

    Thank you.

    - Simon
  2. Yes, the strategy described above is also applicable for Container Managed Transactions. Infact by seeing the variable name 'ctx', I guess that the discussion was about CMT.

     This is how you usually invoke 'setRollbackOnly()'
    CMT
     ejbContext.setRollbackOnly();

    BMT
     UserTransaction transaction = ejbContext.getUserTransaction();
     transaction.rollback() (OR) transaction.setRollbackOnly();
  3. Note that you dont have to do any of this if the exception is a system exception (i.e, not in the method's throws clause) and you are re-throwing it. In that case the container will rollback itself.

    Gal
  4. Yes, this strategy can applicable to CMP. One more thing you need note if you are using Bea Weblogic Server, you must using Tx Data Sources to connect it.

    BaoStone