1 Reply Latest reply on Mar 21, 2011 6:30 AM by Sascha Janz

    session closed

    Sascha Janz Master
      i am using seam 2.2 with jbpm.

      when executing several jbpm command like signal or saveprocessinstance i got an exception "session closed"

      if i execute them via command service bean from jbpm-enterprise.ear everything is ok. where is the difference?

      here are my configurations.

      jbpm

      <jbpm-configuration>

        <jbpm-context>
          <service name="persistence" factory="org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory" />
          <service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
          <service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
          <service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
          <service name="logging" factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
          <service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
        </jbpm-context>

      </jbpm-configuration>


      hibernate

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                               "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
      <hibernate-configuration>
      <session-factory>
        <!-- hibernate dialect -->
        <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
        <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
        <!-- DataSource properties (begin)
      property name="hibernate.connection.datasource">java:comp/env/jdbc/JbpmDataSource</property
      DataSource properties (end)
      DataSource properties (begin) === -->
        <property name="hibernate.connection.datasource">java:/JbpmDS</property>
        <!-- ==== DataSource properties (end)
      JTA transaction properties (begin) -->
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
        <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
        <property name="jta.UserTransaction">java:comp/UserTransaction</property>

       
        <!-- JTA transaction properties (end)
      ..


      an my commmand bean


      import java.sql.Connection;
      import java.sql.SQLException;
      import java.util.List;

      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.ejb.TransactionAttribute;
      import javax.ejb.TransactionAttributeType;

      import org.apache.log4j.Logger;
      import org.jboss.seam.annotations.AutoCreate;
      import org.jboss.seam.annotations.Name;
      import org.jbpm.JbpmConfiguration;
      import org.jbpm.JbpmContext;
      import org.jbpm.command.Command;

      import de.lorenz.soaworkflow.core.performanceprofile.Profiler;

      @Name("CommandService")
      @Stateful
      @AutoCreate
      public class CommandServiceBean  implements CommandService{

           private static final Logger log = Logger.getLogger(CommandServiceBean.class
                     .getName());

           static JbpmConfiguration cfg = JbpmConfiguration
                     .parseResource("resources/jbpm.cfg.xml");

           // AJ 22.1.2010
           // default ist jetzt ohne CommandServiceBean

           @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
           public Object executeCommand(Command cmd) {
                Object returnValue = null;

                log.debug("Begin execute command ");
                long start = 0;
                if (Profiler.isProfiling())
                     start = Profiler.startProfile("CommandBean:executeCommand");
                JbpmContext jbpmContext = null;
                Connection con = null;

                try {
                     // AJ 11.2.2010 muss jedesmal neu erzeugt werden!!!
                     // da n Threads hierauf zugreifen!

                     jbpmContext = cfg.createJbpmContext();

                     // con = ConnectionManager.getInstance().getConnection();
                     // jbpmContext.setConnection(con);

                     if (jbpmContext == null)
                          throw new Exception("Error now jbpm context!");
                     returnValue = cmd.execute(jbpmContext);

                } catch (Exception e) {
                     log.error("Error executeCommand", e);
                } finally {
                     if (jbpmContext != null) {

                          jbpmContext.close();
                          jbpmContext = null;
                          try {
                               if (con != null) {
                                    con.close();
                               }
                          } catch (SQLException e) {
                               // TODO Auto-generated catch block
                               e.printStackTrace();
                          }
                     }

                }

                log.debug("End execute command ");
                if (Profiler.isProfiling())
                     Profiler.endProfile("CommandBean:executeCommand", start);

                return returnValue;

           }
           
           
           @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
           public Object executeCommands(List<Command> cmdlist) {
                Object returnValue = null;

                log.debug("Begin executeCommands ");
                long start = 0;
                if (Profiler.isProfiling())
                     start = Profiler.startProfile("CommandBean:executeCommands");
                JbpmContext jbpmContext = null;
                Connection con = null;

                try {
                     // AJ 11.2.2010 muss jedesmal neu erzeugt werden!!!
                     // da n Threads hierauf zugreifen!

                     jbpmContext = cfg.createJbpmContext();

                     // con = ConnectionManager.getInstance().getConnection();
                     // jbpmContext.setConnection(con);

                     if (jbpmContext == null)
                          throw new Exception("Error now jbpm context!");
                     for ( Command cmd : cmdlist ) {
                          System.out.println("execute "  + cmd.getClass().getName());
                     returnValue = cmd.execute(jbpmContext);
                     }

                } catch (Exception e) {
                     log.error("Error CommandBean:executeCommands", e);
                     
                } finally {
                     if (jbpmContext != null) {

                          jbpmContext.close();
                          jbpmContext = null;
                          try {
                               if (con != null) {
                                    con.close();
                               }
                          } catch (SQLException e) {
                               // TODO Auto-generated catch block
                               e.printStackTrace();
                          }
                     }

                }

                log.debug("End CommandBean:executeCommands");
                if (Profiler.isProfiling())
                     Profiler.endProfile("CommandBean:executeCommands", start);

                return returnValue;

           }

           
           @Remove
           public void remove () {

                System.out.println("remove command service ");
                
           }

      }


      stacktrace

      SignalCommand
      17:39:58,804 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseC
      ordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.i
      ternal.jta.resources.arjunacore.SynchronizationImple@1ee32dd
      org.hibernate.SessionException: Session is closed!
              at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSession
      mpl.java:49)
              at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1258)
              at org.jbpm.db.JobSession$DeleteJobsSynchronization.beforeCompletion(Jo
      Session.java:190)
              at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImpl
      .beforeCompletion(SynchronizationImple.java:114)
              at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompleti
      n(TwoPhaseCoordinator.java:247)
              at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCo
      rdinator.java:86)
              at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
              at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.
      ommitAndDisassociate(TransactionImple.java:1389)
              at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.c
      mmit(BaseTransaction.java:135)
              at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTr
      nsactionManagerDelegate.java:87)
              at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
              at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
              at org.jboss.aspects.tx.TxInterceptor$RequiresNew.invoke(TxInterceptor.
        • 1. Re: session closed
          Sascha Janz Master
          injecting the jbpm-context, instead of creating myselve  solved my problem


                 @In
                   private JbpmContext jbpmContext;
               
               @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
               public Object executeCommands(List<Command> cmdlist) {
                    Object returnValue = null;

                    log.debug("Begin executeCommands ");
                    long start = 0;
                    if (Profiler.isProfiling())
                         start = Profiler.startProfile("CommandBean:executeCommands");

                    try {
                         // AJ 11.2.2010 muss jedesmal neu erzeugt werden!!!
                         // da n Threads hierauf zugreifen!


                         if (jbpmContext == null)
                              throw new Exception("Error now jbpm context!");
                         for ( Command cmd : cmdlist ) {
                              System.out.println("execute "  + cmd.getClass().getName());
                         returnValue = cmd.execute(jbpmContext);
                         }

                    } catch (Exception e) {
                         log.error("Error CommandBean:executeCommands", e);
                    }
                         

                    log.debug("End CommandBean:executeCommands");
                    if (Profiler.isProfiling())
                         Profiler.endProfile("CommandBean:executeCommands", start);

                    return returnValue;

               }