AnsweredAssumed Answered

5.11 breaks creating task & adding group -NeedsActiveTaskCmd

Question asked by sangv on Feb 7, 2013
Latest reply on Feb 13, 2013 by jbarrez
I recently upgraded to 5.11 and find that my working code is now broken.

For a specific usecase, we create a task on the fly from a service task and add a candidate group to it.


public void execute(DelegateExecution delegateExecution) throws Exception {
TaskEntity task = (TaskEntity) taskService.newTask();
          task.setName(name);
          task.setPriority(priority);
          task.setProcessInstanceId(processInstanceId);
        task.setProcessDefinitionId(processDefinitionId);
       …
       
        taskService.saveTask(task);

        for(String group: groups){
             addCandidateGroup(task.getId(), group);
        }
}

But since the upgrade to 5.11, it seems that the NeedsActiveTaskCmd gets invoked which checks against the task entity manager with the task id before allowing the candidate group to be added. However since the saveTask call has not been committed, the task does not exist in the database leading to this exception stack trace.

org.activiti.engine.ActivitiException: Cannot find task with id 196
     at org.activiti.engine.impl.cmd.NeedsActiveTaskCmd.execute(NeedsActiveTaskCmd.java:51)
     at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
     at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:60)
     at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
     at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
     at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
     at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:38)
     at org.activiti.engine.impl.TaskServiceImpl.addCandidateGroup(TaskServiceImpl.java:120)

Since, I am saving the task and adding the candidate group in the same service task (running under the context of activiti's transaction),  the task never gets persisted (even without the candidate group link). So, basically the interceptor now leads to my tasks not being persisted at all.

Basically, my questions is
i) Was this the expected behavior? It seems not to me because this will force me to potentially use 2 async service tasks or start managing multiple transactions within the service task. There was a similar issue reported with creating attachments which seems to have been caused by the same command being invoked. - http://forums.activiti.org/en/viewtopic.php?f=6&t=5718

Comments/Recommendations?

Thanks,
Sang

Outcomes