4 Replies Latest reply on Apr 10, 2006 11:26 AM by hitcher

    contradiction between the Sun tutorial and JBoss-Wiki

    Eitan Gur Newbie

      Hi
      The J2EE Sun tutorial http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Transaction4.html#wp80007 specifically instructs:

      Do not invoke the getRollbackOnly and setRollbackOnly methods of the EJBContext interface in bean-managed transactions. These methods should be used only in container-managed transactions. For bean-managed transactions, invoke the getStatus and rollback methods of the UserTransaction interface.


      However, the JBoss-Wiki page http://wiki.jboss.org/wiki/Wiki.jsp?page=WhatIsTheCorrectPatternForUserTransactions instructs (in the example) to use setRollbackOnly() method:
      UserTransaction ut = ... // e.g. new InitialContext().lookup("java:comp/UserTransaction");
      ut.begin();
      try
      {
      // DO SOMETHING
      }
      catch (Exception e)
      {
       ut.setRollbackOnly(); // Force a rollback for this error
       throw e;
      }
      finally
      {
       if (ut.getStatus() == Status.STATUS_ACTIVE)
       ut.commit();
       else
       ut.rollback();
      }
      


      Can anyone shed some light on this alleged contradiction?

      Thanks