2 Replies Latest reply on Jul 10, 2010 1:40 AM by Felix Jose

    failed to lazily initialize a collection of role: org.jbpm.pvm.internal.model.ExecutionImpl.variables, no session or session was closed

    Felix Jose Newbie

      Hi All,

       

      I am using JBPM with Spring and Hibernate. I am getting the following exception while getting the variables using executionImpl and is as follows:

       

      org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.jbpm.pvm.internal.model.ExecutionImpl.variables, no session or session was closed
      org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
      org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
      org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
      org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
      org.hibernate.collection.PersistentMap.entrySet(PersistentMap.java:242)
      org.jbpm.pvm.internal.model.ScopeInstanceImpl.getVariables(ScopeInstanceImpl.java:237)
      com.jpmc.speadd.service.impl.SpeaddWorkFlow.StartWorkFlow(SpeaddWorkFlow.java:245)

       

      My JBPM-config file snippet:

       

       

       

       

      <command-service name="txRequiredCommandService"> 

       

      <retry-interceptor /> 

      <environment-interceptor />

      <spring-transaction-interceptor />

      </command-service>

       

       

       

      <

       

      transaction-context>

      <transaction type="spring"/>

      <repository-session/>

      <db-session/>

      <message-session/>

      <timer-session/>

      <history-sessions>

      <object class="org.jbpm.pvm.internal.history.HistorySessionImpl"/>

      </history-sessions>

      <!--

      Need to set explicitly that we don't want jbpm to create sessions

      -->

      <hibernate-session current="true" close="false"/>

      </transaction-context>

       

      My application context contains the following:

       

      <

       

      bean id="transactionManager"

       

      class="org.springframework.orm.hibernate3.HibernateTransactionManager">

       

      <property name="sessionFactory" ref="sessionFactory" />

       

      </bean>

       

      <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">

       

      <property name="sessionFactory" ref="sessionFactory"></property>

       

      </bean>

       

       

      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

       

       

      <property name="configLocation" value="/WEB-INF/classes/hibernate.config.xml" />

       

       

      <property name="dataSource" ref="dataSource" />

       

      </bean>

      <

       

      bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">

       

      <property name="jbpmCfg" value="jbpm.cfg.xml"></property>

       

      </bean>

       

       

      <bean id="processEngine" factory-bean="springHelper"

       

      factory-method="createProcessEngine">

       

      </bean>

       

       

       

       

       

      Can you please let me know how can i solve the same? Please send a response as soon as possible.

       

      With Regards,

      Felix K Jose

       

       

       

       

       

       

       

       

        • 1. Re: failed to lazily initialize a collection of role: org.jbpm.pvm.internal.model.ExecutionImpl.variables, no session or session was closed
          Michael Wohlfart Expert

          Hi Felix,

           

          you might need this in  jbpm.cfg.xml:

          [...]

          <command-service name="newTxRequiredCommandService"> 
                      <retry-interceptor /> 
                      <environment-interceptor policy="requiresNew" />
                      <spring-transaction-interceptor policy="requiresNew" />     

          </command-service>

           

          <command-service name="txRequiredCommandService">
                      <retry-interceptor />
                      <environment-interceptor />
                      <spring-transaction-interceptor current="true" />
          </command-service>

          [...]


          also maybe your SpeaddWorkFlow.StartWorkFlow() method needs a @Transactional annotation?

           

          and finally you can try to do whatever you do in line 245 of SpeaddWorkFlow.java within a command like described by HuiSheng in this thread:

          processEngine.execute(new Command() {
              public Object execute(Environment env) {
                  // do something.
                  return null;
              }
          });
          • 2. Re: failed to lazily initialize a collection of role: org.jbpm.pvm.internal.model.ExecutionImpl.variables, no session or session was closed
            Felix Jose Newbie

            HI Michael,

             

            Thank You for your reply. Even I am having the same configuration in my jbpm.cfg.xml file. Then I have tried with reinstantiate the ExecutionService factory as

             

             

            executionService = processEngine.getExecutionService();

            Then after that it starts working. Before I give the transaction management I was getting the lazyinitialization exception while trying to access the properties of the jbpm process variable objects. But after I configure the transaction management as follows:

             

             

            <bean id="jbpmContextServiceTarget" class="com.collabera.poc.jbpm.impl.JBPMContextServiceImpl"

                        init-method="init">

                        <property name="processEngine">

                              <ref bean="processEngine" />

                        </property>

                        <property name="checking">

                              <ref bean="checking" />

                        </property>

            <bean id="jbpmContextService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

                <property name="transactionManager"><ref bean="transactionManager"/></property>

                <property name="target"><ref bean="jbpmContextServiceTarget"/></property>

                <property name="transactionAttributes">

                    <props>

                        <prop key="deploy*">PROPAGATION_REQUIRED</prop>

                        <prop key="*">PROPAGATION_REQUIRED</prop>

                    </props>

                </property>

            </bean>

             

            And try to do a transition using executionService  I am getting the exception saying that "

            Exception in thread "main"

             

            org.jbpm.api.JbpmException: execution ddrRequest.400008 does not exist

            at org.jbpm.pvm.internal.cmd.SignalCmd.execute(

             

            SignalCmd.java:58)

            at org.jbpm.pvm.internal.cmd.SignalCmd.execute(

             

            SignalCmd.java:35)

            at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(

             

            DefaultCommandService.java:42)

            at org.jbpm.pvm.internal.tx.SpringCommandCallback.doInTransaction(

             

            SpringCommandCallback.java:45)

            at org.springframework.transaction.support.TransactionTemplate.execute(

             

            TransactionTemplate.java:128)

            I am getting this exception when I am using the ExecutionService instance to access the process instance.

            In my analysis the problem is as the transaction is active and session is opened the JBPM4_EXECUTION table is not getting updated and the

             

             

             

             

             

             

            executionService

             

             

            .signalExecutionById(id, "analystResearch"); is trying to find the execution istance from table but it is not present. But my doubt is why it is not tring to pick it from session?

             

            One main thing is this problem is occuring only when the JBPM process definition is having a <java> node with some arguments and if we change the variable/variables in that java class.

             

            And one more doubt,

             

            processEngine.execute(new Command() {
                public Object execute(Environment env) {
                    // do something.
                    return null;
                }
            });
            why do we need this?

             

            Can anybody please send me a solution for the same.

             

            Thank you and regards,

            Felix K Jose