8 Replies Latest reply on Feb 13, 2006 8:20 PM by Ian Terrell

    subProcessInstance is null

    Bernd Ruecker Master

      On jbpm 3.0.2 I load a process-instance

      ProcessInstance pi = session.getGraphSession().loadProcessInstance( processId )

      and the Root-Token is definitly in a sub-process. But the call


      returnes null! Is this a hibernate problem? Or some Lazy-Loading issue?

      Any hints on How to get the correct subProcess-Association? Sorry, but I have no time in the current project to delve into the source code....

      Thanks in advance


        • 2. Re: subProcessInstance is null
          Tom Baeyens Master

          i'll have a look and try to reproduce.

          regards, tom.

          • 3. Re: subProcessInstance is null
            Tom Baeyens Master

            This piece of test code seems to succeed in head of cvs (which should be the same as 3.1 beta 3)

            ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
             "<process-definition name='subprocess'>" +
             " <start-state name='start'>" +
             " <transition to='wait' />" +
             " </start-state>" +
             " <state name='wait'>" +
             " <transition to='end' />" +
             " </state>" +
             " <end-state name='end' />" +
             processDefinition = ProcessDefinition.parseXmlString(
             "<process-definition name='superprocess'>" +
             " <start-state name='start'>" +
             " <transition to='sub process state' />" +
             " </start-state>" +
             " <process-state name='sub process state'>" +
             " <sub-process name='subprocess' />" +
             " <variable name='a' access='read' mapped-name='A' />" +
             " <variable name='b' mapped-name='B' />" +
             " <variable name='c' access='write' mapped-name='C' />" +
             " <transition to='wait' />" +
             " </process-state>" +
             " <state name='wait' />" +
             ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("superprocess");
             ...some variable operations...
             long processInstanceId = processInstance.getId();
             long subProcessInstanceId = processInstance.getRootToken().getSubProcessInstance().getId();
             processInstance = jbpmContext.loadProcessInstance(processInstanceId);

            regards, tom.

            • 4. Re: subProcessInstance is null
              Ian Terrell Newbie


              I see you try accessing it in a new transaction; is that also starting a new jbpmSession? I get the error when everything is persisted and I try accessing it in a later session; it works fine when still in the original one.

              I'm using 3.0.2; I tried going to 3.1 beta 3 to test it, but I have a fairly significant code base and migration is a little more complicated than switching out the .jar. :)


              • 5. Re: subProcessInstance is null
                Eduardo Jimenez Newbie

                My comments here apply to 3.0.2. I think that's what you are using, correct me if I'm wrong.

                The subProcessToken is not persistent. Hence when you load the process instance from the DB, its always null.

                Is there something you want to do that you cant accomplish using the subprocess end event?

                See this for reference

                If you implement the code change listed there, you can get the subProcessInstance from the subprocess end event. In our case, that turned out to be a great solution.

                Otherwise, you'll have to change the way you are trying to load the subprocess. One thing you can do is run a custom HQL query to find the process instances that have a superprocesstoken = X. Should be pretty easy to write and if you write it in HQL it will not tie you to the database schema.

                The aforementioned bug should be fixed in a 3.0.3 release in our opinion.

                • 6. Re: subProcessInstance is null
                  Tom Baeyens Master

                  it's scheduled for 3.0.3. i just don't know yet when 3.0.3 will be released.

                  • 7. Re: subProcessInstance is null
                    Ian Terrell Newbie

                    Thanks for the information, guys.

                    • 8. Re: subProcessInstance is null
                      Ian Terrell Newbie


                      Is there something you want to do that you cant accomplish using the subprocess end event?

                      Actually, I think yes. I have a process that uses subprocesses for repetitive tasks like calling someone (with carefully designed business rules for a busy signal, leaving a message, etc). Unfortunately, I also have the requirement that at any given time I must pause the workflow for a user-defined amount of time. The way I've implemented this in my test workflows is to have a hold-state that dynamically creates a timer to leave it.

                      Each larger workflow instance is tied to an entity in our system. So, when they hit "pause" I need to be able to figure out exactly which process they are currently in so that I can pause /that/ subprocess, hence pausing the rest. Otherwise, if I pause the superprocess the subprocess would just get restarted from the beginning upon re-entry.

                      My first approach was, of course, to recursively use .getSubProcessInstance(). I don't have a large urge to write HQL as I like to keep libraries free of customization so that future bugfix releases can be integrated in just by replacing a jar.

                      My guess is that everyone will recommend I migrate my existing code to 3.1, where this is fixed?