AnsweredAssumed Answered

Delete Process Instance doesn't mark end of HistoricProcess instant and loses deleteReason

Question asked by zoenzo on Apr 26, 2013
Latest reply on Apr 30, 2013 by frederikheremans1
I used RuntimeService.deleteProcessInstance to delete some old process instance by using the following code. The reason I add the processDefinition to the DeploymentCache is that they are some old definition and is not in the cache since the system has restarted many times.

         DeploymentCache dc =((ProcessEngineConfigurationImpl)processEngineConfiguration).getDeploymentManager().getProcessDefinitionCache();
         ProcessDefinitionEntity pd =(ProcessDefinitionEntity)dc.get(pi.getProcessDefinitionId());
            pd = (ProcessDefinitionEntity)repositoryService.createProcessDefinitionQuery().processDefinitionId(pi.getProcessDefinitionId()).singleResult();
            dc.add(pi.getProcessDefinitionId(), pd);
            this.runtimeService.deleteProcessInstance(processId,"user delete");
            this.runtimeService.deleteProcessInstance(processId,"user delete");

It throws a exception says that the process install is still running. After debugging, I found out that deleteProcessInstance method does not mark end of the historic process instance which means that the "endTime" field and "DELETE_REASON_" field in the database table "act_hi_procinst" is null after the method invoked.
Therefore, I search the forum and found out this issue is fixed in ACT-1098. But it still doesn't work in my project.
In my case, all the historic tasks are marked end with correct delete reason. But not the historic process instance.
Thus, I went to detail of the implementation code in

public void deleteCascade(String deleteReason) {
    this.deleteReason = deleteReason;
    this.deleteRoot = true;

After reading I haven't found any place in does the "mark end " work.
However, the, in the other hand, has the following code.

public void recordProcessInstanceEnd(String processInstanceId, String deleteReason, String activityId) {
    if(isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
      HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceManager()
      if (historicProcessInstance!=null) {

And the method is called from ExecutionImpl.

org.activiti.engine.impl.history.HistoryManager.recordProcessInstanceEnd(String, String, String)
                org.activiti.engine.impl.interceptor.CommandContext.performOperation(AtomicOperation, InterpretableExecution)

So, what my code doesn't work. And I got confuse of ExecutionImpl with ExecutionEntity.
Or is there any other method to delete a process instance completely.
My version is from 5.8 at the begining and upgrade to 5.10 and to 5.12 now.