6 Replies Latest reply on May 19, 2010 6:26 PM by Teofilo Copa

    [jbpm 4.2] Finding a Process Instance

    Mike Burton Newbie

      How to check or find whether a process instance is started or not for a specific process definition. Is there any API avaialble in jBPM 4.2. I have only process definition id avaialble in my application.

      Please guide me.
      Thanks for your valuable reply.

        • 1. Re: [jbpm 4.2] Finding a Process Instance
          Santanu Saraswati Novice

          org.jbpm.api.ProcessInstanceQuery is the class you should be using.

          ProcessInstanceQuery query = new ProcessInstanceQueryImpl();
          List<ProcessInstance> list = query.processDefinitionId("procesDefinitionId").list();
          


          • 2. Re: [jbpm 4.2] Finding a Process Instance
            Mike Burton Newbie

            Hi Santanu

            Thanks for your respnse.

            When i use this statement in my code, i am getting the below exception.

            org.jbpm.api.JbpmException: no environment to get org.hibernate.Session
            at org.jbpm.pvm.internal.env.Environment.getFromCurrent(Environment.java:196)
            at org.jbpm.pvm.internal.env.Environment.getFromCurrent(Environment.java:189)
            at org.jbpm.pvm.internal.query.AbstractQuery.untypedList(AbstractQuery.java:63)
            at org.jbpm.pvm.internal.query.AbstractQuery.untypedUniqueResult(AbstractQuery.java:68)
            at org.jbpm.pvm.internal.query.ProcessInstanceQueryImpl.uniqueResult(ProcessInstanceQueryImpl.java:43)
            at com.kenexa.core.workflow.CoreWorkflowExecutionService.getCurrentActiveStepName(CoreWorkflowExecutionService.java:228)
            at com.kenexa.core.workflow.CoreWorkflowExecutionService.initiateWorkflow(CoreWorkflowExecutionService.java:71)
            at com.kenexa.perform.web.actions.goals.ManageGoalActionImpl.save(ManageGoalActionImpl.java:130)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:585)

            Then changed the statment from
            ProcessInstanceQuery query = new ProcessInstanceQueryImpl(); to
            ProcessInstanceQueryImpl lProcessInstanceQuery = (ProcessInstanceQueryImpl) WorkflowUtil.getExecutionService().createProcessInstanceQuery();

            I am not sure, is it the correct way of getting ProcessInstanceQuery?

            Also once the ProcessInstance is started, i want to get the current activity name from process instance. Is there any method avaialble in ProcessInstance?

            Please suggest me.

            • 3. Re: [jbpm 4.2] Finding a Process Instance
              Santanu Saraswati Novice

              Hi Mike,
              you caught me. What you did was perfect and my way of creating query is definitely not the correct way. Thanks for pointing that and sorry for giving an incorrect code.

              For the current exception you might need to see if you have <environment-interceptor /> in you command service declaration in jbpm.cfg.xml. EnvironmentInterceptor creates hibernate Session. So try that and let us know if it works.

              Otherwise you can provide the jbpm.cfg you are using. We can check if there is some problem there.

              • 4. Re: [jbpm 4.2] Finding a Process Instance
                Mike Burton Newbie

                Thanks for your reply. <environment-interceptor /> is specified in jbpm.cfg.xml. Here is my complete configuration.

                <jbpm-configuration>
                <process-engine-context>
                <repository-service />
                <repository-cache />
                <execution-service />
                <history-service />
                <management-service />
                <identity-service />
                <task-service />
                <command-service>
                <retry-interceptor />
                <environment-interceptor />
                </command-service>

                <hibernate-configuration>

                </hibernate-configuration>
                <hibernate-session-factory />
                <script-manager default-expression-language="juel"
                default-script-language="juel">
                <script-language name="juel" factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
                </script-manager>

                <id-generator />

                <address-resolver />
                </process-engine-context>
                <transaction-context>
                <repository-session />
                <db-session />
                <message-session />
                <timer-session />
                <history-session />
                </transaction-context>


                </jbpm-configuration>

                Please suggest me if something wrong in this configuration.

                • 5. Re: [jbpm 4.2] Finding a Process Instance
                  Santanu Saraswati Novice

                  Name of the command service and the id-generator are to be changed in 4.2. Yours is for 4.1. But you should have got exception at some other step because of these. This is a sample cfg file for 4.2

                  <jbpm-configuration>
                  
                   <import resource="jbpm.businesscalendar.cfg.xml" />
                   <import resource="jbpm.jpdl.cfg.xml" />
                  
                   <process-engine-context>
                   <repository-service />
                   <repository-cache />
                   <execution-service />
                   <history-service />
                   <management-service />
                   <task-service />
                   <identity-service />
                   <command-service name="txRequiredCommandService">
                   <skip-interceptor />
                   <retry-interceptor />
                   <environment-interceptor />
                   <standard-transaction-interceptor />
                   </command-service>
                  
                   <hibernate-configuration>
                   <cfg resource="jbpm.hibernate.cfg.xml" />
                   </hibernate-configuration>
                  
                   <hibernate-session-factory />
                  
                   <object class="org.jbpm.pvm.internal.id.DatabaseDbidGenerator">
                   <field name="commandService"><ref object="txRequiredCommandService" /></field>
                   </object>
                  
                   <object class="org.jbpm.pvm.internal.id.DatabaseIdComposer" init="eager" />
                  
                   <script-manager default-expression-language="juel" default-script-language="juel">
                   <script-language name="juel" factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
                   </script-manager>
                  
                   <job-executor auto-start="false" />
                  
                   <types resource="jbpm.variable.types.xml" />
                   </process-engine-context>
                  
                   <transaction-context>
                   <repository-session/>
                   <db-session/>
                  
                   <message-session/>
                   <timer-session/>
                   <hibernate-session current="true"/>
                   </transaction-context>
                  
                  </jbpm-configuration>
                  


                  • 6. Re: [jbpm 4.2] Finding a Process Instance
                    Teofilo Copa Newbie

                    Hi at all when iam trying this:

                     

                    ProcessInstanceQuery query = new ProcessInstanceQueryImpl();
                    List<ProcessInstance> list = query.processDefinitionId("procesDefinitionId").list();

                     

                    i get this exception:

                    org.jbpm.api.JbpmException: no environment to get org.hibernate.Session
                         org.jbpm.pvm.internal.env.EnvironmentImpl.getFromCurrent(EnvironmentImpl.java:197)
                         org.jbpm.pvm.internal.env.EnvironmentImpl.getFromCurrent(EnvironmentImpl.java:190)
                         org.jbpm.pvm.internal.query.AbstractQuery.untypedList(AbstractQuery.java:70)
                         org.jbpm.pvm.internal.query.ProcessInstanceQueryImpl.list(ProcessInstanceQueryImpl.java:48)
                         org.uajms.dtic.epersonal.web.controllers.PruebaController.doInicializarVentana(PruebaController.java:67)
                         org.uajms.dtic.epersonal.web.controllers.PruebaController.afterCompose(PruebaController.java:78)
                         org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:620)
                    

                     

                    this is my jbpm.cfg.xml

                     

                    <jbpm-configuration>
                        <import resource="jbpm.default.cfg.xml" />
                        <import resource="jbpm.tx.hibernate.cfg.xml" />
                        <import resource="jbpm.jpdl.cfg.xml" />
                        <import resource="jbpm.bpmn.cfg.xml" />
                        <import resource="jbpm.identity.cfg.xml" />
                        <import resource="jbpm.businesscalendar.cfg.xml" />
                        <import resource="jbpm.console.cfg.xml" />
                        <import resource="jbpm.jobexecutor.cfg.xml" />
                    </jbpm-configuration>

                     

                    am using jbpm-4.3 why i can fix this thanks so.