Search code examples
springbusiness-process-managementbpmncamunda

SetProcessDefinitionVersionCmd is not working


I'm using camunda engine on Spring environment, so I'm trying to change process definition for a process instance just like http://docs.camunda.org/latest/guides/user-guide/#process-engine-process-versioning with:

@Transactional
public void migrateProcessInstance(String processInstanceId, int newVersion) {
    SetProcessDefinitionVersionCmd command =
            new SetProcessDefinitionVersionCmd(processInstanceId, newVersion);
    ((ProcessEngineImpl) processEngine)
                    .getProcessEngineConfiguration()
                    .getCommandExecutorTxRequired().execute(command);
}

But it's not working, it's executed without errors but when I see act_hi_procinst and act_ru_task tables nothing has changed. I've seen the SetProcessDefinitionVersionCmd code and I didn't see any call for update like other commands only a few changes for ExecutionEntity and TaskEntity, is that a bug in SetProcessDefinitionVersionCmd or am I doing something wrong?


Solution

  • This command only updates the current runtime state of the process instance (executions, tasks), such that the process instance continues based on the new process definition.

    It does not update historic process instances/tasks even though they may be currently active. One could argue that the process definition id of these entities always refers to the process definition that was valid at the time of their creation and therefore this behavior is expected.

    edit: Nevertheless my explanation is not mentioned in the official documentation, probably due to the fact that SetProcessDefinitionVersionCmd is not public API and it is the only case in which the process definition can change. However, the docs you link also do not guarantee anything regarding history, so you are probably expecting something that the command does not provide.