1 2 Previous Next 15 Replies Latest reply on Jan 28, 2009 4:09 PM by srlucas Go to original post
      • 15. Re: jbpm 3.2 Session Is Closed exception in JobSession
        srlucas

        Hi,
        I am experiencing the same issue here. I haven't found the solution yet (I might try the posted solution here) but wanted to post the problem for future reference...

        the error I am getting is the following:

        17:53:07,343 [http-8080-4] INFO ContextAdvice : ----------> ContextAdvice in action, opening ctx
        17:53:21,234 [http-8080-4] DEBUG JbpmContextInfo : creating jbpm context with service factories '[tx, message, scheduler, logging, persistence, authentication]'
        17:53:21,250 [http-8080-4] DEBUG JbpmContext : creating org.jbpm.JbpmContext@93f17f
        17:53:21,250 [http-8080-4] INFO ContextAdvice : --------------> reusing existing jbpmContext: org.jbpm.JbpmContext@93f17f
        17:53:26,281 [http-8080-4] DEBUG DbPersistenceServiceFactory : creating persistence service
        17:53:26,296 [http-8080-4] DEBUG DbPersistenceService : creating hibernate session
        17:53:26,296 [http-8080-4] DEBUG DbPersistenceService : beginning hibernate transaction
        17:53:31,343 [http-8080-4] DEBUG DbPersistenceService : begun hibernate transaction org.hibernate.transaction.JDBCTransaction@537c91
        17:53:31,531 [http-8080-4] INFO ContextAdvice : ----------> ContextAdvice in action, closing ctx
        17:53:51,562 [http-8080-4] DEBUG JbpmContext : closing jbpmContext org.jbpm.JbpmContext@93f17f
        17:53:51,578 [http-8080-4] DEBUG Services : closing service 'persistence': org.jbpm.persistence.db.DbPersistenceService@362a7b
        17:53:51,593 [http-8080-4] DEBUG DbPersistenceService : committing hibernate transaction org.hibernate.transaction.JDBCTransaction@537c91
        17:53:51,625 [http-8080-4] DEBUG DbPersistenceService : closing hibernate session
        17:53:51,640 [http-8080-4] DEBUG Services : closing service 'tx': org.jbpm.tx.TxService@384d34
        17:53:51,812 [http-8080-4] ERROR LoggingSession : org.hibernate.SessionException: Session is closed!


        And here is a bit of explanation.
        I have a ContextAdvice Object that opens/closes the context when you enter/leave the service logic.
        package com.ea.dc.jbpm.context;
        
        import java.lang.reflect.Method;
        
        import org.apache.log4j.Logger;
        import org.jbpm.JbpmConfiguration;
        import org.jbpm.JbpmContext;
        import org.springframework.aop.AfterReturningAdvice;
        import org.springframework.aop.MethodBeforeAdvice;
        
        /** Class used to intercept calls to services and initialize the jbpmContext
         * in order to make it transparent to the coder.
         *
         * @author lucas.gonzalezp
         */
        public class ContextAdvice
         implements MethodBeforeAdvice, AfterReturningAdvice {
        
         /** The class logger. */
         private static final Logger LOGGER = Logger.getLogger(ContextAdvice.class);
        
         /** jbpm configuration. */
         private JbpmConfiguration jbpmConfiguration = null;
        
         /** Opens the context. */
         public void before(Method method, Object[] args, Object target)
         throws Throwable {
         LOGGER.info("----------> ContextAdvice in action, opening ctx");
         getContext();
         }
        
        
         /** Closes the context. */
         public void afterReturning(Object returnValue, Method method,
         Object[] args, Object target) throws Throwable {
         LOGGER.info("----------> ContextAdvice in action, closing ctx");
        
         JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
         if (jbpmContext != null) {
         jbpmContext.close();
         } else {
         // TODO: throw exception?
         LOGGER.fatal("----------> CONTEXT NOT FOUND, SOMEONE ELSE CLOSED IT");
         }
         }
        
         /** Looks for a current JBPMContext. If it does not exists it will create
         * a new one.
         * @return a jbpm context
         */
         private JbpmContext getContext() {
         // Lookup the pojo persistence context-builder that is configured above
         JbpmContext jbpmContext = jbpmConfiguration.getCurrentJbpmContext();
        
         if (jbpmContext == null) {
         jbpmContext = jbpmConfiguration.createJbpmContext();
         LOGGER.info("--------------> creating new jbpmContext: "
         + jbpmContext);
         }
         return jbpmContext;
         }
        
         /** Sets the jbpmConfiguration for this bean.
         * @param config the jbpm configuration to set
         */
         public void setJbpmConfiguration(final JbpmConfiguration config) {
         jbpmConfiguration = config;
         }
        }
        


        and here is one of the failing methods:

        public List<JobDTO> getJobs() {
         List<JobDTO> result = new ArrayList<JobDTO>();
        
         // Lookup the pojo persistence context-builder that is configured above
         JbpmContext jbpmContext = getContext();
        
         // let's obtain a graph session to get the process instances
         GraphSession graphSession = jbpmContext.getGraphSession();
         // now let's get the process instance
         ProcessDefinition procDef = graphSession.findLatestProcessDefinition(
         WorkFlowServiceImpl.PROCESS_NAME);
        
         List<ProcessInstance> instances =
         graphSession.findProcessInstances(procDef.getId());
        
         for (Iterator iterator = instances.iterator(); iterator.hasNext();) {
         ProcessInstance processInstance = (ProcessInstance) iterator.next();
         result.add(populateJob(processInstance));
         }
        
         return result;
         }
        


        So I understand that ContextAdvice closes the jbpmContext --> HibernateSession and then the LogSession throws the error.

        Is it possible to flush/close the LogSession before the context is closed?

        thanks,
        Lucas

        - I am using springmodules 0.8a

        1 2 Previous Next