7 Replies Latest reply on Jun 28, 2012 10:51 AM by milhaim

    Human tasks : LocalTaskService JTA issue

    milhaim

      Hi all,

       

      I'm Using JBPM5.2.final in a seam 2 application all running under jboss 5.1 SA.

       

      When a use LocalTaskService as following :

      to connect the service :

       

      public void connect() {
                  if (service == null) {
                      org.jbpm.task.service.TaskService taskService = HumanTaskService.getService();                
                      service = new LocalTaskService(taskService.createSession());
                  }
      ....
      

       

      and I register the human task :

       

                 TaskService taskService = HumanTaskService.getService();     
                  SyncWSHumanTaskHandler handler = new SyncWSHumanTaskHandler(new LocalTaskService(taskService.createSession()), ksession);   
                  ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
      

       

      But when a start my process instance and create a human task I get then the following exception (A JTA EntityManager cannot use getTransaction()) :

      I'm using jboss transaction manager

       

      12:33:59,014 ERROR [STDERR] Caused by: java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
      12:33:59,014 ERROR [STDERR]     at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:324)
      12:33:59,014 ERROR [STDERR]     at org.jbpm.task.service.TaskServiceSession.taskOperation(TaskServiceSession.java:442)
      12:33:59,014 ERROR [STDERR]     at org.jbpm.task.service.local.LocalTaskService.start(LocalTaskService.java:224)
      12:33:59,014 ERROR [STDERR]     at com.atriumnetwork.jbpm.LocalTaskManager.completeTask(LocalTaskManager.java:96)
      

       

      I checked in the sources ther were tow options for TransactionType: default and local-JTA

       

      So I tried to set the transaction type to local-JTA :

       

      taskSession.setTransactionType("local-JTA");
      

       

      This is working when I start my process  but  when  execution other human tasks I get : No active JTA transaction on joinTransaction call exception


      Caused by: java.lang.RuntimeException: javax.persistence.TransactionRequiredException: No active JTA transaction on joinTransaction call
          at org.jbpm.task.service.TaskServiceSession.doOperationInTransaction(TaskServiceSession.java:990)
          at org.jbpm.task.service.TaskServiceSession.taskOperation(TaskServiceSession.java:433)
          at org.jbpm.task.service.local.LocalTaskService.skip(LocalTaskService.java:220)
          at org.jbpm.process.workitem.wsht.SyncWSHumanTaskHandler.abortWorkItem(SyncWSHumanTaskHandler.java:256)
          at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.internalAbortWorkItem(JPAWorkItemManager.java:76)
          at org.jbpm.workflow.instance.node.WorkItemNodeInstance.cancel(WorkItemNodeInstance.java:249)
          at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setState(WorkflowProcessInstanceImpl.java:257)
          at org.jbpm.workflow.instance.node.EndNodeInstance.internalTrigger(EndNodeInstance.java:57)
          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)
      

       

      is there another option for the transaction type ?? 

       

      any help will be very appreciated

        • 1. Re: Human tasks : LocalTaskService JTA issue
          swiderski.maciej

          could you try setting local to true on handler (SyncWSHumanTaskHandler)?

          That way task execution will be executed within the same transaction as process instance.

           

          HTH

          1 of 1 people found this helpful
          • 2. Re: Human tasks : LocalTaskService JTA issue
            milhaim

            setting local to true on the handler solved my issue.

             

            thank you very much.

             

            miloud

            • 3. Re: Human tasks : LocalTaskService JTA issue
              milhaim

              Hi Maciej,

               

              I'm getting the same issue  "No active JTA transaction on joinTransaction call", in another case:

               

              if I create a process instance and restart  my application or the jboss server, and try to close the porcessInstance (and  complite the current human task),

              it works fine for the processinstances newly created (after restarting the app).

               

              do you know if I need to set the local to true (SyncWSHumanTaskHandler) somewhere else.

               

              For the moment I set this variable after loading or creating the StatefulKnowledgeSession.

               

              Thanks for your help.

              • 4. Re: Human tasks : LocalTaskService JTA issue
                swiderski.maciej

                that sounds very weird as can find any reason why it would work only for new processes. Once it is registered on the session that is moving on with the process instance.

                • 5. Re: Human tasks : LocalTaskService JTA issue
                  milhaim

                  After some debugging I found that this exception happened in this conditions:

                   

                  when closing the process instance (reaching the End transition), the TaskServiceSession is called to skip the active human task

                   

                  there is one human task but claimed by a user and the following exception happens.

                   

                  org.jbpm.task.service.PermissionDeniedException: User '[User:'Administrator']' was unable to execution operation 'Skip' on task id 21 due to a no 'current status' match

                   

                  the transaction is marked to rollback, status STATUS_MARKED_ROLLBACK because I'm using Jboss 5 transaction manager

                   

                  this method is called after

                   

                  private void doOperationInTransaction(final TransactedOperation operation) {

                  ....

                  if (ut.getStatus() == javax.transaction.Status.STATUS_NO_TRANSACTION) {

                  .....

                  } else {

                              em.joinTransaction();

                   

                  trying to join a transaction in status  MARKED_ROLLBACK which explains the exception "No active JTA transaction on joinTransaction call"

                   

                  after that I added the code to complete the task successfully. but the TaskServiceSession still excute the skip task, where there is no human tasks.

                   

                  I dont have this probelm if I don't restart the ksession.

                   

                  Thanks.

                  • 6. Re: Human tasks : LocalTaskService JTA issue
                    swiderski.maciej

                    Is it possible to reproduce on a junit test? Like with disposing and restoring session?

                     

                    Could you provide you process definition as I am trying to understand why the skip operation is executed.

                    • 7. Re: Human tasks : LocalTaskService JTA issue
                      milhaim

                      Hi Maciej,

                       

                      Thanks for your help,

                       

                      I tried to debug to understand where does it come form, when skipping this task the status was "Completed" so there was no match with the list of command  'Created', 'Ready', 'InProgress' ...

                       

                      But this does not explain why the task is being skipped in the first place (maybe  a cache issue).

                       

                      I'm trying to move jbpm on mysql db (my application will remain on a postgres db), to check if this have any relation.

                       

                      I will work on the junit test once I finish setting the mysql db (heopfuly by the and of the day),

                       

                      here the  process definition file.