AnsweredAssumed Answered

Querying historic activity instances in the order they were executed

Question asked by jesper1 on Sep 28, 2016
Hello everybody,

In my unit tests, I'm using the HistoryService to do a HistoricActivityInstanceQuery, so that I can check if a process instance went through the expected path. To do this, I need to query the historic activity instances in the order that they were executed. So I'm adding an order criterium, like this:

List<HistoricActivityInstance> activities = historyService.createHistoricActivityInstanceQuery()
        .processInstanceId(processInstanceId)
        .orderByHistoricActivityInstanceStartTime().asc()
        .list();
Unfortunately, ordering by historic activity instance start time does not always work. If activities are executed quickly after each other (in the same millisecond) then the order in which I get activity instances from the query is sometimes different than the order in which they were actually executed.

Another possibility is to order by historic activity instance id (using orderByHistoricActivityInstanceId instead of orderByHistoricActivityInstanceStartTime), which seems to work better than ordering by start time. But are activity instance id's guaranteed to be increasing over time?

What is the best way to do this query and to ensure that I get the activities in the order that they were executed?

I'm using Activiti v5.21.

Outcomes