7 Replies Latest reply on Apr 10, 2006 7:45 AM by koen.aers

    not able to save processInstance

    forjbpm

      Why is method saveProcessInstance is deprecated??

      I am trying to use something like

      [code
      ]public long uploadDocument(String processDefinitionName) {
      long processInstanceId = 0;
      JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession();
      ProcessDefinition processDefinition = jbpmSession.getGraphSession().findLatestProcessDefinition(processDefinitionName);
      System.out.println("processDefinition is"+processDefinition);
      try {
      ProcessInstance processInstance = new ProcessInstance(processDefinition);
      System.out.print("processInstance is "+processInstance);
      Token token = processInstance.getRootToken();
      System.out.println("token is"+token);
      token.signal();
      System.out.println("token.signal() is done");
      System.out.println("now saving GraphSession");
      jbpmSession.getGraphSession().saveProcessInstance(processInstance);
      System.out.println("saved process instance processInstance is"+processInstance);
      processInstanceId = processInstance.getId();
      System.out.println("processInstanceId is : "+processInstanceId);
      } catch (Exception ex) {
      System.out.println("In catch method");
      }
      return processInstanceId;
      }

      output for this is
      17:14:57,774 INFO [STDOUT] processDefinition isProcessDefinition(StandardJbpmPlugin)
      17:14:57,783 INFO [STDOUT] processInstance is org.jbpm.graph.exe.ProcessInstance@1a08f39
      17:14:57,784 INFO [STDOUT] now saving GraphSession
      17:14:57,784 INFO [STDOUT] In catch method


        • 1. Re: not able to save processInstance
          forjbpm

          ooops!
          My Question was
          If this is not right method then how should I save my processInstance.

          In my code (for which output is given)

          Token token = processInstance.getRootToken();
          System.out.println("token is"+token);
          token.signal();
          System.out.println("token.signal() is done");

          is commented.

          Please help!


          • 2. Re: not able to save processInstance
            qweniden

            the "save()" method on the JbpmContext class accepts an instance to be saved.

            • 3. Re: not able to save processInstance
              forjbpm

              Do you think taht instead of using jbpmSession and JbpmSessionFactory, I should use JbpmConfiguration and jbpmContext?

              Please suggest.
              Whats the plan!

              • 4. Re: not able to save processInstance
                forjbpm

                ok!
                One more thing!
                I followed qweniden's suggestion. and changed my method to

                public long uploadDocument(String processDefinitionName) {
                 long processInstanceId = 0;
                
                 JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
                 System.out.println("jbpmContext is:"+jbpmContext);
                 ProcessDefinition processDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition(processDefinitionName);
                 try {
                 ProcessInstance processInstance =
                 new ProcessInstance(processDefinition);
                 System.out.print("processInstance is "+processInstance);
                 Token token = processInstance.getRootToken();
                 System.out.println("now saving GraphSession");
                 GraphSession graphSession = jbpmContext.getGraphSession();
                 System.out.println("graphSession is "+graphSession);
                 //saving jbpmContext
                 jbpmContext.save(processInstance);
                 System.out.println("saved process instance processInstance is"+processInstance);
                
                 processInstanceId = processInstance.getId();
                 System.out.println("processInstanceId is : "+processInstanceId);
                
                 } catch (Exception ex) {
                 System.out.println("In catch method ");
                 }
                 return processInstanceId;
                 }


                output for this is as expected
                10:04:16,652 INFO [STDOUT] jbpmContext is:org.jbpm.JbpmContext@4845f3
                10:04:16,785 INFO [STDOUT] processInstance is org.jbpm.graph.exe.ProcessInstance@19c03e7
                10:04:16,785 INFO [STDOUT] now saving GraphSession
                10:04:16,785 INFO [STDOUT] graphSession is org.jbpm.db.GraphSession@179e567
                10:04:16,788 INFO [STDOUT] saved process instance processInstance isorg.jbpm.graph.exe.ProcessInstance@19c03e7
                10:04:16,788 INFO [STDOUT] processInstanceId is : 478
                



                but when I look in my database there is no entry in jbpm_processinstance for id_ =478



                • 5. Re: not able to save processInstance
                  forjbpm

                  huh!
                  Okay! I found out that
                  i have to save jbpmContext (jbpmContext.save()) before returning processInstanceID and then it saves the processInstance.

                  Still I would like to ask,
                  Should I use jbpmSessionFactory and jbpmSession at all?
                  and as JbpmConfiguration is static can I use it in my ejbcreate() and use it? ( I mean thats the way I am doing it now)

                  Thanks and regards,

                  • 6. Re: not able to save processInstance
                    forjbpm

                    oops! its jbpmContext.close() not jbpmContext.save()

                    • 7. Re: not able to save processInstance
                      koen.aers

                      You should use JbpmContext instead of JbpmSessionFactory and JbpmSession, which are deprecated. And yes, you can use JbpmConfiguration in your ejbCreate.

                      Regards,
                      Koen