3 Replies Latest reply on Mar 12, 2008 10:05 AM by Deji Mabogunje

    context variables not being persisted

    Deji Mabogunje Newbie

      I have jbpm set up using the in memory HSQL DB. I have written a simple unit test creating process variables on the context instance loke so :

      ProcessDefinition definition = jbpmContext.getGraphSession().getProcessDefinition(Long.parseLong(instanceTO.getTemplateId()));
      ProcessInstance instance = new ProcessInstance(definition);
      ContextInstance contextInstance = (ContextInstance) instance.getInstance(ContextInstance.class);
      contextInstance.setVariable(name,"name");
      contextInstance.setVariable(test,"test");
      jbpmContext.save(instance);

      However when I load the instance again, those variables do not exist. Debugging into my code I find that when the variables are created they exist in a transientInstances list while the instances list remains null.

      I dont know why these variables are not being persisted. any ideas ?

      Thanks

        • 2. Re: context variables not being persisted
          Deji Mabogunje Newbie

          Actually I am closing the context, here is the full code :

          JbpmContext jbpmContext = s_jbpmConfiguration.createJbpmContext();
          try
          {
          ProcessDefinition definition = jbpmContext.getGraphSession().getProcessDefinition(Long.parseLong(instanceTO.getTemplateId()));
          ProcessInstance instance = new ProcessInstance(definition);
          ContextInstance contextInstance = (ContextInstance)instance.getInstance(ContextInstance.class);
          contextInstance.setVariable("name","name");
          contextInstance.createVariable("test","test");
          jbpmContext.save(instance);
          }
          catch (Exception e)
          {
          throw new WorkflowEngineException(e.getMessage(), e);
          }
          finally
          {
          jbpmContext.close();
          }


          Also when I look in the ProcessInstance object during runtime, there are instances and transientInstances, however instances remains null, while transient instance contains my ContextInstance and LoggingInstance. As I add variables, they are being added to my transient instance. Is that correct ? That seems like the reason they are not being persisted but I dont know why its happening.

          Thanks for all your help

          • 3. Re: context variables not being persisted
            Deji Mabogunje Newbie

            Well it seems like when I create the process definition by parsing the xml definition everything works fine.

            What I was trying to do was programmatically create my process definition. By creating a new process definition object and adding nodes and transitions to it.

            Note that in both scenarios the resulting instances are identical except for the fact that in one case the instance variables a transient and thus not saved.

            Any thoughts on why this might be happening ? There arent any examples on creating a ProcessDefinition programmatically.