0 Replies Latest reply on Feb 2, 2006 10:47 AM by sy62k

    Error: Already marked for rollback

      Hi,

      I am receiving the following error intermittently:

      javax.transaction.RollbackException: Already marked for rollback TransactionImpl:XidImpl

      The Transaction manager code I have written is as follows:

      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.rmi.PortableRemoteObject;
      import javax.transaction.HeuristicMixedException;
      import javax.transaction.HeuristicRollbackException;
      import javax.transaction.NotSupportedException;
      import javax.transaction.RollbackException;
      import javax.transaction.Status;
      import javax.transaction.SystemException;
      import javax.transaction.UserTransaction;
      
      import org.apache.log4j.Logger;
      
      import com.prototypeit.exception.DAORuntimeException;
      
      public class TransactionManager {
      
       private static UserTransaction transaction = null;
       private static Logger log = Logger.getLogger(TransactionManager.class);
      
       public static void begin(){
      
       try {
       InitialContext ctx = new InitialContext();
       debug("Beginning a User transaction");
       if(transaction == null){
       debug("Transaction is null. So doing a new lookup to fetch the UserTransaction!");
       Object o = ctx.lookup("java:comp/UserTransaction");
       transaction = (UserTransaction)PortableRemoteObject.narrow(o, UserTransaction.class);
       }
       debug("Transaction Status Before begin(): "+transaction.getStatus());
       if(transaction.getStatus() == Status.STATUS_NO_TRANSACTION){
       debug("invoking transaction.begin");
       transaction.begin();
       }
       debug("Transaction Status After begin(): "+transaction.getStatus());
       } catch (NamingException e) {
       log.error(e.getMessage());
       throw new DAORuntimeException(e);
       } catch (NotSupportedException e) {
       log.error(e.getMessage());
       throw new DAORuntimeException(e);
       } catch (SystemException e) {
       log.error(e.getMessage());
       throw new DAORuntimeException(e);
       }
       }
      
       public static void commit(){
       if(transaction != null){
       try {
       debug("The Status while committing: "+ transaction.getStatus());
       transaction.commit();
       debug("The Status After committing: "+ transaction.getStatus() );
       } catch (SecurityException e) {
       log.error(e.getMessage());
       rollback();
       throw new DAORuntimeException(e);
       } catch (IllegalStateException e) {
       log.error(e.getMessage());
       rollback();
       throw new DAORuntimeException(e);
       } catch (RollbackException e) {
       log.error(e.getMessage());
       rollback();
       throw new DAORuntimeException(e);
       } catch (HeuristicMixedException e) {
       log.error(e.getMessage());
       rollback();
       throw new DAORuntimeException(e);
       } catch (HeuristicRollbackException e) {
       log.error(e.getMessage());
       rollback();
       throw new DAORuntimeException(e);
       } catch (SystemException e) {
       log.error(e.getMessage());
       rollback();
       throw new DAORuntimeException(e);
       }
       }
      
       }
      
       public static void rollback(){
      
       if(transaction != null){
      
       try {
       debug("The Status while rolling back: "+ transaction.getStatus());
       transaction.rollback();
       debug("The Status after rolling back: "+ transaction.getStatus());
       } catch (IllegalStateException e) {
       log.error(e.getMessage());
       throw new DAORuntimeException(e);
       } catch (SecurityException e) {
       log.error(e.getMessage());
       throw new DAORuntimeException(e);
       } catch (SystemException e) {
       log.error(e.getMessage());
       throw new DAORuntimeException(e);
       }
      
       }
       }
      
       public static void debug(String message){
       if(log.isDebugEnabled()){
       log.debug(message);
       }
       }
      }
      


      Any help is very much appreciated,
      Thanks a lot,
      -H