As we try to migrate the process we keep getting this error:
2020-09-21 15:05:22,320 [default task-1] ERROR org.flowable.common.engine.impl.interceptor.CommandContext Error while closing command context org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: com.microsoft.sqlserver.jdbc.SQLServerException: The DELETE statement conflicted with the REFERENCE constraint "ACT_FK_TIMER_JOB_PROCESS_INSTANCE". The conflict occurred in database "WF", table "i2sflow.ACT_RU_TIMER_JOB", column 'PROCESS_INSTANCE_ID_'.
### The error may exist in org/flowable/db/mapping/entity/Execution.xml
### The error may involve org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl.deleteExecution-Inline
### The error occurred while setting parameters
### SQL: delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: The DELETE statement conflicted with the REFERENCE constraint "ACT_FK_TIMER_JOB_PROCESS_INSTANCE". The conflict occurred in database "WF", table "i2sflow.ACT_RU_TIMER_JOB", column 'PROCESS_INSTANCE_ID_'.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:212)
at org.flowable.common.engine.impl.db.DbSqlSession.flushDeleteEntities(DbSqlSession.java:569)
at org.flowable.common.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:526)
at org.flowable.common.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:293)
at org.flowable.common.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:191)
at org.flowable.common.engine.impl.interceptor.CommandContext.close(CommandContext.java:61)
at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:81)
at org.flowable.common.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:56)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:56)
at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51)
at org.flowable.engine.impl.RuntimeServiceImpl.migrateProcessInstancesOfProcessDefinition(RuntimeServiceImpl.java:777)
at org.flowable.engine.impl.migration.ProcessInstanceMigrationBuilderImpl.migrateProcessInstances(ProcessInstanceMigrationBuilderImpl.java:108)
at pt.i2s.fwk.workflow.processes.beans.ProcessDefinitionMigrationService.migrateProcessInstances(ProcessDefinitionMigrationService.java:54)
at pt.i2s.fwk.workflow.services.impl.WorkflowProcessesServicesImpl.migrateProcessInstances(WorkflowProcessesServicesImpl.java:165)
... 73 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The DELETE statement conflicted with the REFERENCE constraint "ACT_FK_TIMER_JOB_PROCESS_INSTANCE". The conflict occurred in database "WF", table "i2sflow.ACT_RU_TIMER_JOB", column 'PROCESS_INSTANCE_ID_'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:254)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1608)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:578)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:508)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7240)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2869)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:243)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:218)ni
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:493)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.execute(WrappedPreparedStatement.java:442)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
... 88 more
At first i thought that i was doing something wrong, so i double checked everything, the processes were fine but with more investigation we found out that the query that the engine was trying to do was “ delete from ACT_RU_EXECUTION where ID_ = ‘58b804eb-15b5-11ea-b7a8-00155dfc8176’ and REV_ = 2 ” and this query is what is causing the error.
For that process instance in question we have 2 records on the table ACT_RU_EXECUTION and the process migration fails due to a FK constraint as we can see here:
Some more information about this process, it has a timer job and after the timer a sub process is called with a single service task in it.
Also, we are using Flowable 6.4.2.
How can i solve this problem?
Thanks in advance.