4 Replies Latest reply on Mar 21, 2009 7:55 AM by Ronald van Kuijk

    Sub processe definition is null

    psmith Newbie

      There seems to be an issue running processes outside of the container when they contain sub-process. The following code is a simple test that has one process with a contained node that is a sub-process. This code produces the following error:

      Exception in thread "main" org.jbpm.JbpmException: can't create a process instance when processDefinition is null

      package com.mincom.ellipse.test;
      
      import org.jbpm.graph.def.ProcessDefinition;
      import org.jbpm.graph.exe.ProcessInstance;
      
      public class SubProcessTest {
      
       public static void main(String[] args) {
       ProcessDefinition superDef = ProcessDefinition.parseXmlString("<?xml version=\"1.0\" encoding=\"UTF-8\"?><process-definition xmlns=\"\" name=\"super\"><start-state name=\"start-state1\"><transition to=\"node1\"></transition></start-state><node name=\"node1\"><transition to=\"process-state1\"></transition></node> <process-state name=\"process-state1\"><sub-process name=\"sub\"></sub-process><transition to=\"end-state1\"></transition></process-state><end-state name=\"end-state1\"></end-state></process-definition>");
       ProcessDefinition subDef = ProcessDefinition.parseXmlString("<?xml version=\"1.0\" encoding=\"UTF-8\"?><process-definition xmlns=\"\" name=\"sub\"><start-state name=\"start-state1\"><transition to=\"node1\"></transition></start-state><node name=\"node1\"><transition to=\"end-state1\"></transition></node><end-state name=\"end-state1\"></end-state></process-definition>");
       ProcessInstance superInst = new ProcessInstance(superDef);
       ProcessInstance subInst = new ProcessInstance(subDef);
      
       while(!superInst.hasEnded()) {
       superInst.signal();
       }
       }
      }
      


      I've done some reading about this and it seems that the JbpmContext must be initialised and any sub process definitions loaded before the super process is called and signalled. However what do you do if you are unit testing the process or indeed running processes that are not long running or deployed to the database?

        • 1. Re: Sub processe definition is null
          psmith Newbie

          I found a solution to this based on another post and that was to do the following

           ProcessState superState = (ProcessState) superDef.getNode("process-state1");
           superState.setSubProcessDefinition(subDef);
          


          This seems realy yuk. If the parent process knows that it has a sub-process why can't it just load the definition. At the very least you could have the xml location as an attribute of the subProcess node.

          • 2. Re: Sub processe definition is null
            Ronald van Kuijk Master

            I disagree that it is 'yuk'. You mention yourself that you (want to try to) run *outside* of the container, container being the jBPM 'engine' via a jbpm 'context' (I doubt you will succeed). If you deploy a processdefinition (even just to an in memory db), the container does resolve dependencies for you.

            • 3. Re: Sub processe definition is null
              psmith Newbie

              Why should I need a database (even an in memory one) to run short running processes? If you specified a subprocess and resolvable process xml then everything should be sweet without a database.

              • 4. Re: Sub processe definition is null
                Ronald van Kuijk Master

                I don't say you need a database to run things, I just say that the jbpm container resolves subprocess dependencies when you *deploy* them. Since you do not deploy them, there is no resolver and you have to associate the two yourself.

                the 'I doudbt you would' success was indeed a bit harsh and not directed at you, but a remark in general which I now think is not completely valid. What I wanted to express is why not just associate the two via an api if you know they are related instead of trying to make resolvers or whatever.