cancel
Showing results for 
Search instead for 
Did you mean: 

Sort problem on activi historic table (sort by id)

lestat86
Champ in-the-making
Champ in-the-making
Hi everyone,

I recently discovered what might be a bug in the activity historic table (act_hi_actinst). In my application i need to display the last activity executed by a certain process, so what i've done for the past month is using this code to get it:


getHistoryService().
createHistoricActivityInstanceQuery().
processInstanceId(processId).
orderByHistoricActivityInstanceId().
desc().
list().
get(0).
getActivityName();


It worked fine until now, when the method gives me not the last but the second to last activity. I noticed that it is because the id of the very last is 100036, while the second to last is 99856. This case was replicated several times, and i think that it behaves the way it does because the id field is a varchar(64), so the lexicographic sort kicks in.

Why use a varchar instead of a serial then? Is this something done on purpose or a mistake?

Thanks a lot

Alberto



2 REPLIES 2

trademak
Star Contributor
Star Contributor
Hi Alberto,

We wanted to support alternative id generators that might not produce only numeric ids as well.
So it's not a mistake. But for these use cases a numeric column type would have been a better fit.
The best way to do sorting would be using starting and end time.

Best regards,

lestat86
Champ in-the-making
Champ in-the-making
Wow, so fast! Thanks for the reply.

I see. My problem with the end time is that sometimes the end time of very quick tasks match up to the millisecond, so it doesn't really work.
I've created a procedure based on both criteria (id and end time) and it is working, i was just curious on this choice of field type.

Thanks again!

Alberto