1 Reply Latest reply on Feb 11, 2006 1:23 AM by Eduardo Jimenez

    Trouble getting SubProcessInstance in new jbpmSession

    Ian Terrell Newbie

      I'm having a little bit of trouble accessing a subprocess instance via a Token's getSubProcessInstance method.

      I'm using the processes:

      <process-definition name='Task Master Process'>
       <start-state name='start'>
       <transition name='go' to='before task' />
       </start-state>
       <state name='before task'>
       <transition name='continue' to='task' />
       </state>
       <process-state name="task">
       <sub-process name="Task Subprocess" />
       <transition to="after task" />
       </process-state>
       <state name='after task'>
       <transition name='continue' to='end' />
       </state>
       <end-state name='end' />
      </process-definition>
      


      <process-definition name="Task Subprocess">
       <swimlane name='task doer'>
       <assignment class='workflow.TaskAssignmentHandler' />
       </swimlane>
       <start-state name="start">
       <transition name="go" to="task" />
       </start-state>
       <task-node name='task'>
       <task name='mytask' swimlane='task doer' />
       <transition name='continue' to='end' />
       </task-node>
       <end-state name="end"/>
      </process-definition>
      


      The following code creates a ProcessInstance, advances it to enter the subprocess, and prints out the subprocess instance in one session, and then loads the process and prints out the subprocess instance (using the same code) in a second session.

      jbpmSession = JbpmSessionFactory.getInstance().openJbpmSession();
      GraphSession graphSession = jbpmSession.getGraphSession();
      
      ProcessDefinition pd = graphSession.findLatestProcessDefinition("Task Master Process");
      ProcessInstance pi = pd.createProcessInstance();
      graphSession.saveProcessInstance(pi);
      
      long id = pi.getId();
      Token t = pi.getRootToken();
      pi.signal();
      pi.signal();
      System.out.println(graphSession.loadProcessInstance(id).getRootToken().getSubProcessInstance());
      jbpmSession.close();
      
      jbpmSession = JbpmSessionFactory.getInstance().openJbpmSession();
      graphSession = jbpmSession.getGraphSession();
      System.out.println(graphSession.loadProcessInstance(id).getRootToken().getSubProcessInstance());
      jbpmSession.close();
      


      This leads to, for example:
      16:39:35,213 INFO [STDOUT] org.jbpm.graph.exe.ProcessInstance@173ccd9
      16:39:35,229 INFO [STDOUT] null
      


      Now, I would very much expect to get the same process instance back even in a new jbpmSession. Instead, I get null. Can anyone shed any light on this?