3 Replies Latest reply on Dec 3, 2014 7:47 AM by Partha Pal

    Workflow transaction boundary

    Partha Pal Newbie

      I am using jbpm-5.4.0.Final in one of our workflow application. A workflow contains only sequence of user tasks. I've put ksession.startPocess(...) and myobject.completeTask(...) in a single transaction boundary using @Transactional  as below

       

      @Transactional

      public void completeInitialTask(){

      ksession.startPocess(...);

      myobject.completeTask(...) ; //completes Ready tasks

      }

       

      But the issue is the statement myobject.completeTask(...) is not working because it is not able to find the Ready tasks.But if I remove the @Transactional annotation it works perfectly. How to commit / rollback two statements as a group.

        • 1. Re: Workflow transaction boundary
          Maciej Swiderski Master

          this is most likely caused by persistence context not able to find entities created/updated in single transaction due to flush mode set to COMMIT on entity manager.

           

          Although the use case you showed looks weird to me. Since you have a user task how is that possible to do the completion of the task directly when it was created - without user interaction? If it's not user that should work on a task consider to use another type of task like service task or domain specific task.

           

          HTH

          • 2. Re: Workflow transaction boundary
            Partha Pal Newbie

            Thanks for the reply Maciej, Here is the actual code

             

            @Transactional

            public ITaskResponse submitForApproval(String businesskey, String group,
                                                       String user,
                                                       String approver) throws WorkflowException {
                    long pid;
                    if (isWorkflowRunning(businesskey)) {

                        pid = getProcessInstanceId(businesskey);
                    } else if (isWorkflowNew(businesskey)) {
                       pid = getEngine().startBusinessProcess(getBPMNProcessId(), null);
                    } else {
                        throw new WorkflowException("Workflow instance for " +
                                                    businesskey + " already exists");
                    }
                    completeTask(WorkflowConstant.TASK_SUBMIT, pid, user, group,
                                         null);
            }

             

            To complete the very first task of the workflow, I need to start the flow and complete the task in a single transactional block so that in case of any issue everything will be rolled back. completeTask method uses LocalTaskService to start and complete the task. How to do these in single transaction?

            • 3. Re: Workflow transaction boundary
              Partha Pal Newbie

              I found the answer. I've used request scoped session strategy. Inside the same transaction, if more than one different sessions involved, then it did not work properly. Then I aligned the session with transaction and now it is working properly.