0 Replies Latest reply on Jun 26, 2006 3:58 AM by Susumu Majima

    Transaction rollback in JBOSS/SEAM

    Susumu Majima Newbie

      I read seam1.0.0.CR3 DVDStore sample. And I tried to do rollback test.
      I think the default transaction mode is REQUIRED so we don't need to write declarative transaction at the method.

      As my understanding there are three types of coding for roolback.

      1) Call setRollbackOnly()
      2) Anotate @ApplicationException(roolbak=true) for exception trigers rollback
      3) Generate System Exception

      I write the program for checking #1. The database is MySQL 4.0.26. Seam is 1.0.0CR3. JBOSS is 4.0.4GA.
      But it doesn't work. "Transaction is not active" is returned.

      Does anybody success to rollback in SEAM?


      What I do is

      I added the below in faces-config.xml

      <lifcycle>
       <phase-listner>org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListner
       </phase-linstner>
      </lifecycle>
      
      


      I added the below in web.xml
      <filter>
       <filter-name>Seam Exception Filter</filter-name>
       <filter-class>org.jboss.seam.servlet.SeamExceptionFilter</filter-class>
      </filter>
      
      <filter-mapping>
       <filter-name>Seam Exception Filter</filter-name>
       <url-pattern>/*</url-pattern>
      </filter-mapping>
      


      The program is
      package org.jboss.seam.example.NCI_GW.ejb;
      
      import org.jboss.seam.example.NCI_GW.par.*;
      
      import java.util.*;
      
      // add 0620 for Transaction -----------------------------------
      import org.jboss.seam.contexts.Context;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Transactional;
      import javax.annotation.Resource;
      import javax.ejb.*;
      import org.jboss.seam.annotations.Conversational;
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.util.Transactions;
      import javax.transaction.UserTransaction;
      import javax.naming.NameNotFoundException;
      import javax.naming.NamingException;
      
      
      import org.jboss.seam.annotations.Scope;
      import static org.jboss.seam.ScopeType.*;
      import javax.ejb.Stateless;
      import javax.ejb.Stateful;
      import javax.faces.application.FacesMessage;
      import javax.faces.context.FacesContext;
      import javax.faces.model.SelectItem;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.annotations.Name;
      
      import org.jboss.logging.Logger;
      
      import static javax.persistence.PersistenceContextType.EXTENDED;
      import static javax.persistence.PersistenceContextType.TRANSACTION;
      import javax.ejb.Remove;
      import org.jboss.seam.annotations.Destroy;
      
      @Stateful
      @Scope(EVENT)
      @Name("dspForumRoomSession")
      public class DspForumRoomSessionBean implements DspForumRoomSession
      {
       private static final Logger log = Logger.getLogger(DspForumRoomSessionBean.class);
      
       @PersistenceContext(type=EXTENDED)
       private EntityManager em;
       boolean result;
      
       @Resource
       SessionContext ctx; // Declare SessionContext
      
      
       public boolean createForum(Forum forum) // Register Forum table
       {
       try {
       em.persist(forum);
       result = true;
       } catch (Exception e1) {
       e1.printStackTrace();
       result = false;
       }
      // 0622 for Transaction -------------------------------------------
      rollBack();
       return result;
       }
      
      
       public boolean rollBack() // Try rollback
       {
       try {
       ctx.setRollbackOnly();
       result = true;
       } catch (Exception e1) {
       e1.printStackTrace();
       result = false;
       }
       return result;
       }
      
      
      
       @Destroy @Remove
       public void destroy() {}
      
      }
      


      The snipped of server.log is
      2006-06-26 16:21:08,025 DEBUG [org.hibernate.pretty.Printer] org.jboss.seam.example.NCI_GW.par.Forum{level=1, forumid=1004, edtsubject=???????????06/06/26 16:21?, userid=sasaki, edtchainid=null, crtdatetime=2006-06-26 16:21:07, username=???, subject=???, comment=???, countcomment=0, chainid=9999999999}
      2006-06-26 16:21:08,025 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
      2006-06-26 16:21:08,025 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
      2006-06-26 16:21:08,035 DEBUG [org.jboss.util.NestedThrowable] org.jboss.util.NestedThrowable.parentTraceEnabled=true
      2006-06-26 16:21:08,035 DEBUG [org.jboss.util.NestedThrowable] org.jboss.util.NestedThrowable.nestedTraceEnabled=false
      2006-06-26 16:21:08,035 DEBUG [org.jboss.util.NestedThrowable] org.jboss.util.NestedThrowable.detectDuplicateNesting=true
      2006-06-26 16:21:08,035 DEBUG [org.hibernate.util.JDBCExceptionReporter] Cannot open connection [???]
      org.jboss.util.NestedSQLException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=NCI-074/27, BranchQual=, localId=27]; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=NCI-074/27, BranchQual=, localId=27])
      


      Any information is helpful.

      Susumu