1 2 Previous Next 15 Replies Latest reply on Jan 28, 2009 4:09 PM by Lucas Gonzalez

    jbpm 3.2 Session Is Closed exception in JobSession

    Mark Anderson Newbie

      Hi. At the end of processing a Task node along with a few regular nodes, we're getting a "Session is closed" hibernate exception in jbpm 3.2 JobSession class. I'm not sure what to look for here. Ideas? A configuration issue maybe? I did not see other instances of this in Forum or JIRA searches.

      JBPM 3.2 on JBoss 4.0.5 with EJB3 and JBoss Messaging configuration

      Hibernate Config:

      hibernate.dialect: org.hibernate.dialect.SQLServerDialect
      hibernate.connection.datasource: java:/jdbc/jbpm
      hibernate.transaction.factory_class: org.hibernate.transaction.JTATransactionFactory
      hibernate.transaction.manager_lookup_class: org.hibernate.transaction.JBossTransactionManagerLookup
      

      JBPM Config:
      <service name="persistence">
       <factory>
       <bean class="org.jbpm.persistence.db.DbPersistenceServiceFactory">
       <field name="isCurrentSessionEnabled"><false /></field>
       <field name="isTransactionEnabled"><false /></field>
       </bean>
       </factory>
       </service>
      


      Partial trace up to and including the exception:
      2007-04-06 17:56:32,796 [http-0.0.0.0-8080-3] DEBUG org.jbpm.graph.exe.Token - token[19] is unlocked by token[19]
      2007-04-06 17:56:32,796 [http-0.0.0.0-8080-3] DEBUG org.jbpm.graph.node.Decision - decision Check_Prepare_PPP_Request_Blk is taking 'Transition(wfEnd_eq_YES)'
      2007-04-06 17:56:32,796 [http-0.0.0.0-8080-3] DEBUG org.jbpm.graph.def.GraphElement - event 'node-leave' on 'Decision(Check_Prepare_PPP_Request_Blk)' for 'Token(/)'
      2007-04-06 17:56:32,796 [http-0.0.0.0-8080-3] DEBUG org.jbpm.graph.def.GraphElement - event 'transition' on 'Transition(wfEnd_eq_YES)' for 'Token(/)'
      2007-04-06 17:56:32,811 [http-0.0.0.0-8080-3] DEBUG org.jbpm.graph.def.GraphElement - event 'node-enter' on 'Node(UPES_Obtain_PPP_Internal_Fees)' for 'Token(/)'
      2007-04-06 17:56:32,811 [http-0.0.0.0-8080-3] DEBUG org.jbpm.graph.exe.Token - token[19] is locked by job[2]
      2007-04-06 17:56:32,811 [http-0.0.0.0-8080-3] DEBUG org.jbpm.graph.def.GraphElement - event 'after-signal' on 'ProcessState(Prepare_PPP_Request_Blk (sub))' for 'Token(/)'
      2007-04-06 17:56:32,811 [http-0.0.0.0-8080-3] DEBUG org.jbpm.scheduler.ejbtimer.EjbSchedulerService - deleting timers for process instance org.jbpm.graph.exe.ProcessInstance@12062da
      2007-04-06 17:56:32,827 [http-0.0.0.0-8080-3] DEBUG org.jbpm.scheduler.ejbtimer.TimerServiceBean - deleting timers for process instance org.jbpm.graph.exe.ProcessInstance@12062da from the ejb timer service
      2007-04-06 17:56:32,843 [http-0.0.0.0-8080-3] DEBUG org.jbpm.graph.def.GraphElement - event 'after-signal' on 'TaskNode(Prepare PPP Request (ACTOR))' for 'Token(/)'
      2007-04-06 17:56:32,843 [http-0.0.0.0-8080-3] DEBUG org.jbpm.JbpmContext - closing JbpmContext
      2007-04-06 17:56:32,843 [http-0.0.0.0-8080-3] DEBUG org.jbpm.svc.Services - closing service 'persistence': org.jbpm.persistence.db.DbPersistenceService@1b0c0b8
      2007-04-06 17:56:32,843 [http-0.0.0.0-8080-3] DEBUG org.jbpm.persistence.db.DbPersistenceService - flushing hibernate session
      2007-04-06 17:56:32,874 [http-0.0.0.0-8080-3] DEBUG org.jbpm.persistence.db.DbPersistenceService - closing hibernate session
      2007-04-06 17:56:32,874 [http-0.0.0.0-8080-3] DEBUG org.jbpm.svc.Services - closing service 'message': org.jbpm.msg.jms.JmsMessageServiceImpl@1a1d061
      2007-04-06 17:56:32,874 [http-0.0.0.0-8080-3] DEBUG org.jbpm.svc.Services - closing service 'scheduler': org.jbpm.scheduler.ejbtimer.EjbSchedulerService@bcecc7
      2007-04-06 17:56:32,874 [http-0.0.0.0-8080-3] DEBUG org.jbpm.scheduler.ejbtimer.EjbSchedulerService - removing the timer service session bean
      2007-04-06 17:56:32,874 [http-0.0.0.0-8080-3] DEBUG org.jbpm.svc.Services - closing service 'tx': org.jbpm.tx.TxService@15d13c3
      2007-04-06 17:56:32,874 [http-0.0.0.0-8080-3] DEBUG org.jbpm.svc.Services - closing service 'logging': org.jbpm.logging.db.DbLoggingService@1bc7b65
      2007-04-06 17:56:32,874 [http-0.0.0.0-8080-3] DEBUG org.jbpm.db.JobSession - deleting timers for process instance org.jbpm.graph.exe.ProcessInstance@12062da
      2007-04-06 17:56:32,921 [http-0.0.0.0-8080-3] ERROR com.ourcompany.ourproject.struts.actions.PPPMethodSubmitAction: com.ourcompany.ourproject.utility.LoggableEJBException: java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=rl001-m0152bits/71, BranchQual=, localId=71] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.SessionException: Session is closed!)
      at com.ourcompany.ourproject.utility.ExceptionLogUtil.createLoggableEJBException(ExceptionLogUtil.java:13)
      at com.ourcompany.ourproject.struts.actions.PPPMethodSubmitAction.execute(PPPMethodSubmitAction.java:220)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.ourcompany.ourproject.filters.CheckUserSession.doFilter(CheckUserSession.java:263)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Unknown Source)
      Caused by: java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=rl001-m0152bits/71, BranchQual=, localId=71] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.SessionException: Session is closed!)
      at org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:198)
      at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:180)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:211)
      at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
      at $Proxy129.submitPPPForm(Unknown Source)
      at com.ourcompany.ourproject.struts.actions.PPPMethodSubmitAction.execute(PPPMethodSubmitAction.java:153)
      ... 29 more
      Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=rl001-m0152bits/71, BranchQual=, localId=71] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.SessionException: Session is closed!)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:372)
      at org.jboss.tm.TxManager.commit(TxManager.java:240)
      at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
      ... 47 more
      Caused by: org.hibernate.SessionException: Session is closed!
      at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
      at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1258)
      at org.jbpm.db.JobSession$DeleteJobsSynchronization.beforeCompletion(JobSession.java:190)
      at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
      at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
      ... 49 more


      Thanks.

        • 1. Re: jbpm 3.2 Session Is Closed exception in JobSession
          Matt Read Newbie

          We are getting something similar - it seems that the Transaction Synchronization that is being added is re-using the Session provided when the JobSession is constructed rather than using DBPersistenceService to get it's own.

          Does that sound like it might match your problem?

          • 3. Re: jbpm 3.2 Session Is Closed exception in JobSession
            Ronald van Kuijk Master

            solution to what? The session being closed can be caused by many different reasons, among which are ones in your code. So it is is hard for us to say 'yes', 'no' or provide a solution.

            • 4. Re: jbpm 3.2 Session Is Closed exception in JobSession
              Kalyani Bharde Newbie

              Hi,
              Have you managed to solve your problem?
              I am also facing same problem and on forums I can see some more posts with same problem but cannot see solution anywhere?
              Thanks


              • 5. Re: jbpm 3.2 Session Is Closed exception in JobSession
                Ronald van Kuijk Master

                probably because no-one ever explained what they were doing (see my previous answer)

                • 6. Re: jbpm 3.2 Session Is Closed exception in JobSession
                  buldoser Newbie

                  Hi.
                  I have the same problem.
                  This is code :

                  public void cancelProcess(Long prId) throws RemoteException{
                  JbpmContext ctx = createBpmContext();
                  try{
                  ProcessInstance prInst = ctx.getProcessInstanceForUpdate(prId);
                  prInst.end();
                  }catch (Exception ex) {
                  //...
                  } finally{
                  ctx.close();
                  }
                  }

                  Transaction is managed outside method (for example by using Spring annotations).
                  So problem is following: Session is closed in ctx.close(), transaction commited later, which causes DeleteJobsSynchronization to execute. It reasonably fails, because of closed session.

                  • 7. Re: jbpm 3.2 Session Is Closed exception in JobSession
                    sdfsdf sdfgdfgd Newbie

                    Hi, have you found a solution for the problem?

                    I'm having exactly the same issue.

                    thx,
                    tiz

                    • 8. Re: jbpm 3.2 Session Is Closed exception in JobSession
                      Rex Sheridan Newbie

                      I found a solution to my particular version of this problem yesterday. What I figured out is the hibernate Session is closed by closing the jBPM context before the transaction is committed. In my particular scenario I had a Session Bean backed web service (i.e. JBossWS) and an interceptor (declared through the javax.interceptors.Interceptor annotation) opening/closing the JbpmContext with every business method invocation.

                      The weird thing is that this problem only occurs with the DeleteJobsSynchronization class inside org.jbpm.db.JobSession. This synchronization only seems to occur when a task close or cancel causes the process to end.

                      I can't recommend a general solution for everyone else but mine was fixed by using a javax.xml.ws.handler.Handler to wrap the web service invocations instead of a javax.interceptors.Interceptor.

                      • 9. Re: jbpm 3.2 Session Is Closed exception in JobSession
                        zbyszek Newbie

                        Hi,

                        I encountered the same problem in spring-managed transactions environment (on jboss 4.2.2)
                        Here is the solution:
                        I register DeleteJobsSynchronization within TransactionSynchronizationManager and extend
                        DeleteJobsSynchronization to support Ordered interface. It allows TransactionSynchronizationManager
                        to execute DeleteJobsSynchronization before SpringSessionSynchronization which closes hibernate session.

                        public class SpringJobSession extends JobSession {
                        
                         Log log = LogFactory.getLog(SpringJobSession.class);
                        
                         protected Session session;
                        
                         public SpringJobSession(Session pSession) {
                         super(pSession);
                         // super.session is private...
                         session = pSession;
                         }
                        
                         public void deleteJobsForProcessInstance(ProcessInstance processInstance) {
                         try {
                         // we register synchronization within TransactionSynchronizationManager!
                         TransactionSynchronizationManager.registerSynchronization(
                         new DeleteJobsSynchronization(processInstance));
                         } catch (Exception e) {
                         log.error(e);
                         throw new JbpmException("couldn't delete jobs for '"+processInstance+"'", e);
                         }
                         }
                        
                         // The very important issue here is that TransactionSynchronizationManager,
                         // within DeleteJobsSynchronization is registered, uses particular order
                         // while performing registered synchronizations. The order is specified by
                         // 'Ordered' interface. We have to set lower value than is specified for
                         // SpringSessionSynchronization to force execution of this synchronization
                         // before SpringSessionSynchronization will close the hibernate session.
                         private class DeleteJobsSynchronization extends TransactionSynchronizationAdapter implements Serializable {
                         private static final long serialVersionUID = 1L;
                         ProcessInstance processInstance;
                         public DeleteJobsSynchronization(ProcessInstance processInstance) {
                         this.processInstance = processInstance;
                         }
                         public void beforeCompletion() {
                         log.debug("deleting timers for process instance "+processInstance);
                         Query query = session.getNamedQuery("JobSession.deleteTimersForProcessInstance");
                         query.setParameter("processInstance", processInstance);
                         int result = query.executeUpdate();
                         log.debug(Integer.toString(result)+" remaining timers for '"+processInstance+"' are deleted");
                         System.out.println(" -> 2 < ------");
                         log.debug("deleting execute-node-jobs for process instance "+processInstance);
                         query = session.getNamedQuery("JobSession.deleteExecuteNodeJobsForProcessInstance");
                         query.setParameter("processInstance", processInstance);
                         result = query.executeUpdate();
                         log.debug(Integer.toString(result)+" remaining execute-node-jobs for '"+processInstance+"' are deleted");
                         System.out.println(" -> 3 < ------");
                         }
                        
                         @Override
                         public int getOrder() {
                         // SpringSessionSynchronization.getOrder() returns SessionFactoryUtils.SESSION_SYNCHRONIZATION_ORDER.
                         return SessionFactoryUtils.SESSION_SYNCHRONIZATION_ORDER - 50;
                         }
                         }
                        }
                        


                        public class SpringPersistenceService extends DbPersistenceService {
                        
                         public SpringPersistenceService(SpringPersistenceServiceFactory pPersistentServiceFactory) {
                         super(pPersistentServiceFactory);
                         }
                        
                         public JobSession getJobSession() {
                         if (jobSession==null) {
                         Session session = getSession();
                         if (session!=null) {
                         jobSession = new SpringJobSession(session);
                         }
                         }
                         return jobSession;
                         }
                        
                        }
                        


                        <jbpm-configuration>
                         ....
                         <jbpm-context>
                         <service name="persistence"
                         factory="xxxx.workflow.jbpm.service.SpringPersistenceServiceFactory"/>
                         ....
                         </jbpm-context>
                        


                        Should I create a jira bug for it or rather inform spring guys about this issue ?

                        regards



                        • 10. Re: jbpm 3.2 Session Is Closed exception in JobSession
                          Ronald van Kuijk Master

                          See http://www.jboss.org/index.html?module=bb&op=viewtopic&t=128111, sounds like a more generic bug. Please file a jira issue (sorry for the delayed response)

                          • 11. Re: jbpm 3.2 Session Is Closed exception in JobSession
                            <todo> <todo> Newbie

                            Have anybody tried the following configuration:



                            I have used CMT transactions working with XADataSource. It works.

                            • 12. Re: jbpm 3.2 Session Is Closed exception in JobSession
                              <todo> <todo> Newbie

                              Configuration:

                              <service name="persistence" factory="org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory" />


                              • 13. Re: jbpm 3.2 Session Is Closed exception in JobSession
                                Atanas Krachev Newbie

                                Hello,

                                One solution that worked for me is:
                                In components.xml

                                <persistence:hibernate-session-factory name="jbpmSessionFactory" />
                                <persistence:managed-hibernate-session name="jbpmSession"
                                auto-create="true"
                                scope="CONVERSATION"
                                session-factory="#{jbpmSessionFactory}" />

                                In hibernate.cfg.xml
                                <hibernate-configuration>
                                <session-factory name="java:/jbpmSessionFactory">

                                false
                                after_transaction

                                In jbpm.cfg.xml
                                <jbpm-context>









                                The Seam code that calls the Stateless Session bean facade over jBPM is
                                has appropriate @Begin @End annotations (to mark the Conversation)

                                In the jBPM Stateless Session Facade:

                                @In JbpmContext jbpmContext;

                                @In(value="jbpmSession")
                                Session session;

                                ...
                                public void startProcess(String processName, String key) {
                                jbpmContext.setSession(session);

                                _________________
                                Hope this will help you,
                                Atanas Krachev

                                • 14. Re: jbpm 3.2 Session Is Closed exception in JobSession
                                  Ronald van Kuijk Master

                                  Thanks, but could you post again with the xml in [ c o d e ] tags (without the spaces)

                                  1 2 Previous Next