9 Replies Latest reply on Nov 5, 2011 5:12 AM by amin-mc

    jBPM 5: how save a ProcessInstance ?

    jbpm5learner

      In jBPM 4 it works that way: JbpmContext::save(ProcessInstance). How does it work in jBPM 5 ?

        • 1. Re: jBPM 5: how save a ProcessInstance ?
          eaa

          In jBPM5, processInstance is saved automatically when it reaches a wait-state. There is no way to persist it on-demand.

          You can find more information about process persistence in the documentation manual:

          http://hudson.jboss.org/hudson/job/jBPM5/lastStableBuild/artifact/jbpm-distribution/target/jbpm-5.1-SNAPSHOT-docs-build/jbpm-docs/html_single/index.html#d0e2517

          • 2. Re: jBPM 5: how save a ProcessInstance ?
            jbpm5learner

            The fact that the processInstance is automatically saved may be convenient. But doing some investigation on the jbpm5-source I found some interesting code examples that may offer explicit saving of a ProcessInstance:

             

             

            EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa");

            JpaProcessPersistenceContextManager procPersistMgr = new JpaProcessPersistenceContextManager(env););

             

            ProcessPersistenceContext persistContext = procPersistMgr.getProcessPersistenceContext();

            persistContext.persist(procInfo);

             

            The "ProcessPersistenceContext" allows to persist a so-called ProcessInstanceInfo-object. This object contains a ProcessInstance-object. Are you consequently sure that there is no way to persist  ProcessInstance on-demand ?

             

             

             

            • 3. Re: jBPM 5: how save a ProcessInstance ?
              jbpm5learner

              Sorry, my code example was incomplete - this is the correction of how to create the env-object:

               

              EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");

              Environment env = KnowledgeBaseFactory.newEnvironment();

               

              env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );

               

              • 4. Re: jBPM 5: how save a ProcessInstance ?
                amin-mc

                Hi

                 

                I have a use case where I will need to update the process instance variables after the process engine has reached teh safe point.  I then need to persist the updated process instance.  Is the above the only approach?  Is there no other API available?

                 

                Thanks

                • 5. Re: jBPM 5: how save a ProcessInstance ?
                  salaboy21

                  What exactly are you trying to achieve? why do you need to modify the process variables after a wait state?

                  I mean, if you reach a wait state it means that you are waiting for some external executions, that external service will return some that that will be feed into the process engine that will be in charge of mapping those results with the process variables. I don't see any case where you need to update externally the process variables.

                   

                  Cheers

                  • 6. Re: jBPM 5: how save a ProcessInstance ?
                    amin-mc

                    Hi

                     

                    Basically I need to get to a wait state...make a call to an external service which returns some value which I then needs to be mapped back to a process instance variable. 

                    • 7. Re: jBPM 5: how save a ProcessInstance ?
                      amin-mc

                      Hi

                       

                      I would really appreciate if some could advise on this...i have an important usecase that requires the ability to do this.

                       

                       

                      Thanks

                      • 8. Re: jBPM 5: how save a ProcessInstance ?
                        calca

                        Well, I think you could model it with an event. After the process reached a wait state, you can have a catching event node, so when you get the response from the external service, you can make a session.signalEvent("theevent", eventData) and update the process variables you need inside the process.

                         

                        Anyway, it would be good to know a bit more about your business requirement in order to give a good advice.

                         

                        Regards,

                         

                        Demian

                        • 9. Re: jBPM 5: how save a ProcessInstance ?
                          amin-mc

                          Hi

                           

                          I'm not sure if the event mechanism would work.  Essentially we have to accumulate operations to a remote service during the execution of the process instance.  Once the process reaches a safe point I need to flush the accumulated operations to the external service.  Once the external service returns a result I have to go back and update the process instance variables so the process instance variables are up to date during the next execution.

                           

                          Originally each of my custom service handlers would make individual calls and get a response and update the process instance but this approach is not efficient and causes some transaction issues (long and difficult story to explain ).

                           

                          Thanks