javasqlmonitoringalfrescoactiviti

Activiti HistoricProcessInstanceQuery returned with missing processVariables


I am trying to query HistoricProcessInstances from Activiti historyService including the processVariables. But some of the processes have missing variables in the returned list. I have monitored the database to see the sql query that Activiti had been created, and it turned out, the query joins 3 tables together, and can only return 20 000 records. I have approximately 550 processes with 37 processVariables each, so that's going to be 20 350 records.

In the monitored SQL query there is a rnk (rank) created to each line in the result and its always between 1 and 20 000.

...from ACT_HI_PROCINST RES
            left outer join ACT_HI_VARINST VAR ON RES.PROC_INST_ID_ = VAR.EXECUTION_ID_ and VAR.TASK_ID_ is null
            inner join ACT_HI_VARINST  A0 on RES.PROC_INST_ID_ = A0.PROC_INST_ID_
            WHERE                       RES.END_TIME_ is not NULL and 
                    A0.NAME_= 'processOwner'and 
                    A0.VAR_TYPE_ = 'string' and 
                    A0.TEXT_  = 'user123' 
        ) RES 
    ) SUB WHERE SUB.rnk >= 1 AND 
                SUB.rnk < 20001 and 

Is there any possible solution that I can increase this threshold or create a HistoricProcessInstanceQuery with include only specific processVariables?

My code snippet for the query:

processHistories = historyService.createHistoricProcessInstanceQuery()
                            .processDefinitionKey(processKey).variableValueEquals(VariableNames.processOwner, username)
                            .includeProcessVariables().finished().orderByProcessInstanceStartTime().desc().list();

Solution

  • You can use NativeQuery from HistoryService.createNativeHistoricProcessInstanceQuery enter your SQL (copy from the actual historic process instance query without ranks where clause)