AnsweredAssumed Answered

Activiti TaskQuery query = processEngine.getTaskService().createTaskQuery() returns stale results

Question asked by alin on Apr 9, 2016
Latest reply on Apr 20, 2016 by jbarrez
Hi,

I have searched through the forum and ran across similar issues but none specific to what I am seeing.

My scenario is pretty simple.

// I query the task I want to update.
Task task = taskService.createTaskQuery().taskId(id).singleResult();

// I update the task
task.setAssignee("new assignee");

// I save the task
taskService.saveTask(task);

// I then read the task again,
Task task = taskService.createTaskQuery().taskId(id).singleResult();

// ## here is where I notice that the task.getAssignee() does not return the "new assignee" that I have just saved
// I create a do-while loop here to keep querying until I see the task has the same assignee I have saved..
1) Question here, how do we know when the task that we have sent of to be saved is "complete"? If I read it immediately, is it expected not to be done? (I am using an H2 database here for activity)

// Now after the do-while in a later part of the process I attempt to query for the task with "new assignee" as the assigned user
TaskQuery query = taskService.createTaskQuery(); 
query.taskAssignee("new assignee");
List<Task> list = query.list();

// When I look at the list here I see that the Task objects that are returned are the old objects Task instance that were previous to saving the task and confirming the change with the do-while loop. IF I wait and try the same query later I get the correct date I expect.

2) How is this possible? I do not have caching turned on. I am curious how other people handle the asynchronous calls that are taking place? Any suggestions or tips would be appreciated.

Outcomes