3 Replies Latest reply on Jun 17, 2009 4:16 AM by kukeltje

    How to get the ProcessInstance for a Task in jBpm 4.0 CR1?

    ahmy

      Hello All,

      I am using the TaskService to get the user tasks but in the Task object there is no reference to the ProcessInstance.
      my question if I have a Task object , How I get the ProcessInstance for this Task?

      Thanks,

        • 1. Re: How to get the ProcessInstance for a Task in jBpm 4.0 CR

          How about this...

          TaskImpl task = (TaskImpl) taskService.getTask(is);

          task.getProcessInstance().getDbid();

          • 2. Re: How to get the ProcessInstance for a Task in jBpm 4.0 CR
            ahmy

            I tried the above code but I am getting the following exception

            org.hibernate.LazyInitializationException <init>
            SEVERE: could not initialize proxy - no Session
            org.hibernate.LazyInitializationException: could not initialize proxy - no Session
            


            I think the exception results from the Hibernate Session being closed after callling any TaskService method,
            Is there another way?

            • 3. Re: How to get the ProcessInstance for a Task in jBpm 4.0 CR
              kukeltje

              the new jBPM console does this:

              
               TaskService taskService = processEngine.getTaskService();
               Task task = taskService.getTask(taskId);
              
               // access the processdefition
               TaskImpl cast = ((TaskImpl) task);
               ExecutionImpl processInstance = cast.getProcessInstance();
               String processInstanceId = processInstance.getId();
               String processId = processInstance.getProcessDefinition().getId();
              
              


              The difference being the 'getId()' instead of 'getDbId()'