SQL errors on case reactivation


#1

I am trying to reactivate the case and getting SQL errors.

Case has a human task, I disable the task to move case to state COMPLETED. I then reenable the task and reactivate the case. The reactivate api does not throw any exception with respect to invalid state transition, however there are a lot of SQL errors and state transition does not happen.

Errors:

Disabling Activity Type: humanTask
ReEnabling Activity Type: humanTask
Manual Start Activity Type: humanTask
ReActivating Activity Type: casePlanModel
09-Jan-2018 12:09:27.751 SEVERE [pool-2-thread-1] org.camunda.commons.logging.BaseLogger.logError ENGINE-16004 Exception while closing command context: ENGINE-03004 Exception while executing Database Operation ‘DELETE CaseExecutionEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]’ with message ’

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))

The error may involve org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity.deleteCaseExecution-Inline

The error occurred while setting parameters

SQL: delete from ACT_RU_CASE_EXECUTION where ID_ = ? and REV_ = ?

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))’. Flush summary:

[
INSERT HistoricJobLogEventEntity[d6e5a60b-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricJobLogEventEntity[d6e5a60c-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricTaskInstanceEventEntity[d6e5a606-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricIdentityLinkLogEventEntity[d6e5a607-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[Task_054zohx:d5b144b5-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[d5b144b4-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[d6e5a609-f507-11e7-b892-3210b3b4fa36]
INSERT ExecutionEntity[d6e5a608-f507-11e7-b892-3210b3b4fa36]
INSERT TaskEntity[d6e5a606-f507-11e7-b892-3210b3b4fa36]
INSERT TimerEntity[d6e5a60a-f507-11e7-b892-3210b3b4fa36]
DELETE EventSubscriptionEntity[af0c8988-f507-11e7-b892-3210b3b4fa36]
DELETE TimerEntity[af0c898a-f507-11e7-b892-3210b3b4fa36]
DELETE_BULK deleteByteArrayNoRevisionCheck d43af858-f507-11e7-b892-3210b3b4fa36
UPDATE CaseExecutionEntity[af0c8975-f507-11e7-b892-3210b3b4fa36]
DELETE CaseExecutionEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]
DELETE CaseExecutionEntity[af0c8982-f507-11e7-b892-3210b3b4fa36]
UPDATE ExecutionEntity[af0a3f75-f507-11e7-b892-3210b3b4fa36]
DELETE ExecutionEntity[af0c8987-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricActivityInstanceEventEntity[ExclusiveGateway_14wh46b:af0c8989-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseActivityInstanceEventEntity[af0c8982-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseActivityInstanceEventEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseInstanceEventEntity[af0c8975-f507-11e7-b892-3210b3b4fa36]
]
org.camunda.bpm.engine.ProcessEngineException: ENGINE-03004 Exception while executing Database Operation ‘DELETE CaseExecutionEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]’ with message ’

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))

The error may involve org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity.deleteCaseExecution-Inline

The error occurred while setting parameters

SQL: delete from ACT_RU_CASE_EXECUTION where ID_ = ? and REV_ = ?

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))’. Flush summary:

[
INSERT HistoricJobLogEventEntity[d6e5a60b-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricJobLogEventEntity[d6e5a60c-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricTaskInstanceEventEntity[d6e5a606-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricIdentityLinkLogEventEntity[d6e5a607-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[Task_054zohx:d5b144b5-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[d5b144b4-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[d6e5a609-f507-11e7-b892-3210b3b4fa36]
INSERT ExecutionEntity[d6e5a608-f507-11e7-b892-3210b3b4fa36]
INSERT TaskEntity[d6e5a606-f507-11e7-b892-3210b3b4fa36]
INSERT TimerEntity[d6e5a60a-f507-11e7-b892-3210b3b4fa36]
DELETE EventSubscriptionEntity[af0c8988-f507-11e7-b892-3210b3b4fa36]
DELETE TimerEntity[af0c898a-f507-11e7-b892-3210b3b4fa36]
DELETE_BULK deleteByteArrayNoRevisionCheck d43af858-f507-11e7-b892-3210b3b4fa36
UPDATE CaseExecutionEntity[af0c8975-f507-11e7-b892-3210b3b4fa36]
DELETE CaseExecutionEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]
DELETE CaseExecutionEntity[af0c8982-f507-11e7-b892-3210b3b4fa36]
UPDATE ExecutionEntity[af0a3f75-f507-11e7-b892-3210b3b4fa36]
DELETE ExecutionEntity[af0c8987-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricActivityInstanceEventEntity[ExclusiveGateway_14wh46b:af0c8989-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseActivityInstanceEventEntity[af0c8982-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseActivityInstanceEventEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseInstanceEventEntity[af0c8975-f507-11e7-b892-3210b3b4fa36]
]
at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.flushDbOperationException(EnginePersistenceLogger.java:115)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:305)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flush(DbEntityManager.java:281)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:203)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:132)
at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:113)
at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66)
at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:36)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:29)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:88)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:57)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.ibatis.exceptions.PersistenceException:

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))

The error may involve org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity.deleteCaseExecution-Inline

The error occurred while setting parameters

SQL: delete from ACT_RU_CASE_EXECUTION where ID_ = ? and REV_ = ?

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))

    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:154)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:165)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.executeDelete(DbSqlSession.java:188)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.deleteEntity(DbSqlSession.java:173)
    at org.camunda.bpm.engine.impl.db.AbstractPersistenceSession.executeDbOperation(AbstractPersistenceSession.java:45)
    at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:303)
    ... 13 more

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1039)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1362)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)
… 18 more

09-Jan-2018 12:09:27.798 WARNING [pool-2-thread-1] org.camunda.commons.logging.BaseLogger.logWarn ENGINE-14006 Exception while executing job af0c898a-f507-11e7-b892-3210b3b4fa36:
org.camunda.bpm.engine.ProcessEngineException: ENGINE-03004 Exception while executing Database Operation ‘DELETE CaseExecutionEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]’ with message ’

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))

The error may involve org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity.deleteCaseExecution-Inline

The error occurred while setting parameters

SQL: delete from ACT_RU_CASE_EXECUTION where ID_ = ? and REV_ = ?

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))’. Flush summary:

[
INSERT HistoricJobLogEventEntity[d6e5a60b-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricJobLogEventEntity[d6e5a60c-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricTaskInstanceEventEntity[d6e5a606-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricIdentityLinkLogEventEntity[d6e5a607-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[Task_054zohx:d5b144b5-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[d5b144b4-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[d6e5a609-f507-11e7-b892-3210b3b4fa36]
INSERT ExecutionEntity[d6e5a608-f507-11e7-b892-3210b3b4fa36]
INSERT TaskEntity[d6e5a606-f507-11e7-b892-3210b3b4fa36]
INSERT TimerEntity[d6e5a60a-f507-11e7-b892-3210b3b4fa36]
DELETE EventSubscriptionEntity[af0c8988-f507-11e7-b892-3210b3b4fa36]
DELETE TimerEntity[af0c898a-f507-11e7-b892-3210b3b4fa36]
DELETE_BULK deleteByteArrayNoRevisionCheck d43af858-f507-11e7-b892-3210b3b4fa36
UPDATE CaseExecutionEntity[af0c8975-f507-11e7-b892-3210b3b4fa36]
DELETE CaseExecutionEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]
DELETE CaseExecutionEntity[af0c8982-f507-11e7-b892-3210b3b4fa36]
UPDATE ExecutionEntity[af0a3f75-f507-11e7-b892-3210b3b4fa36]
DELETE ExecutionEntity[af0c8987-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricActivityInstanceEventEntity[ExclusiveGateway_14wh46b:af0c8989-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseActivityInstanceEventEntity[af0c8982-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseActivityInstanceEventEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseInstanceEventEntity[af0c8975-f507-11e7-b892-3210b3b4fa36]
]
at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.flushDbOperationException(EnginePersistenceLogger.java:115)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:305)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flush(DbEntityManager.java:281)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:203)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:132)
at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:113)
at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66)
at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:36)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:29)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:88)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:57)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.ibatis.exceptions.PersistenceException:

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))

The error may involve org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity.deleteCaseExecution-Inline

The error occurred while setting parameters

SQL: delete from ACT_RU_CASE_EXECUTION where ID_ = ? and REV_ = ?

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))

    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:154)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:165)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.executeDelete(DbSqlSession.java:188)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.deleteEntity(DbSqlSession.java:173)
    at org.camunda.bpm.engine.impl.db.AbstractPersistenceSession.executeDbOperation(AbstractPersistenceSession.java:45)
    at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:303)
    ... 13 more

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1039)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1362)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)
… 18 more

09-Jan-2018 12:09:27.829 WARNING [pool-2-thread-1] org.camunda.commons.logging.BaseLogger.logWarn ENGINE-14006 Exception while executing job af0c898a-f507-11e7-b892-3210b3b4fa36:
org.camunda.bpm.engine.ProcessEngineException: ENGINE-03004 Exception while executing Database Operation ‘DELETE CaseExecutionEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]’ with message ’

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))

The error may involve org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity.deleteCaseExecution-Inline

The error occurred while setting parameters

SQL: delete from ACT_RU_CASE_EXECUTION where ID_ = ? and REV_ = ?

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))’. Flush summary:

[
INSERT HistoricJobLogEventEntity[d6e5a60b-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricJobLogEventEntity[d6e5a60c-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricTaskInstanceEventEntity[d6e5a606-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricIdentityLinkLogEventEntity[d6e5a607-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[Task_054zohx:d5b144b5-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[d5b144b4-f507-11e7-b892-3210b3b4fa36]
INSERT HistoricActivityInstanceEventEntity[d6e5a609-f507-11e7-b892-3210b3b4fa36]
INSERT ExecutionEntity[d6e5a608-f507-11e7-b892-3210b3b4fa36]
INSERT TaskEntity[d6e5a606-f507-11e7-b892-3210b3b4fa36]
INSERT TimerEntity[d6e5a60a-f507-11e7-b892-3210b3b4fa36]
DELETE EventSubscriptionEntity[af0c8988-f507-11e7-b892-3210b3b4fa36]
DELETE TimerEntity[af0c898a-f507-11e7-b892-3210b3b4fa36]
DELETE_BULK deleteByteArrayNoRevisionCheck d43af858-f507-11e7-b892-3210b3b4fa36
UPDATE CaseExecutionEntity[af0c8975-f507-11e7-b892-3210b3b4fa36]
DELETE CaseExecutionEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]
DELETE CaseExecutionEntity[af0c8982-f507-11e7-b892-3210b3b4fa36]
UPDATE ExecutionEntity[af0a3f75-f507-11e7-b892-3210b3b4fa36]
DELETE ExecutionEntity[af0c8987-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricActivityInstanceEventEntity[ExclusiveGateway_14wh46b:af0c8989-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseActivityInstanceEventEntity[af0c8982-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseActivityInstanceEventEntity[af0c8984-f507-11e7-b892-3210b3b4fa36]
UPDATE HistoricCaseInstanceEventEntity[af0c8975-f507-11e7-b892-3210b3b4fa36]
]
at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.flushDbOperationException(EnginePersistenceLogger.java:115)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:305)
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flush(DbEntityManager.java:281)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:203)
at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:132)
at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:113)
at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66)
at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:36)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:29)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:88)
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:57)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.ibatis.exceptions.PersistenceException:

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))

The error may involve org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity.deleteCaseExecution-Inline

The error occurred while setting parameters

SQL: delete from ACT_RU_CASE_EXECUTION where ID_ = ? and REV_ = ?

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))

    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:154)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:165)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.executeDelete(DbSqlSession.java:188)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.deleteEntity(DbSqlSession.java:173)
    at org.camunda.bpm.engine.impl.db.AbstractPersistenceSession.executeDbOperation(AbstractPersistenceSession.java:45)
    at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:303)
    ... 13 more

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (camunda.act_ru_task, CONSTRAINT ACT_FK_TASK_CASE_EXE FOREIGN KEY (CASE_EXECUTION_ID_) REFERENCES act_ru_case_execution (ID_))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1039)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1362)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)
… 18 more

Java Code:

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.CaseService;
import org.camunda.bpm.engine.runtime.CaseInstance;
import org.camunda.bpm.engine.runtime.CaseExecution;
import org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity;

import com.opencsv.bean.CsvToBeanBuilder;
import java.io.FileReader;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

public class DisableReEnableCarePlanCaseInstance implements JavaDelegate {

private final static Logger LOGGER = Logger.getLogger(“CKD-CARE-PLANS”);

public void execute(DelegateExecution execution) throws Exception {
LOGGER.info(“Disabling ReEnabling Case Instance . . .”);

    String caseInstanceId = (String) execution.getVariable("caseInstanceId");
    CaseService caseService = execution.getProcessEngineServices().getCaseService();
    List<CaseExecution> caseExecutions = caseService.createCaseExecutionQuery().caseInstanceId(caseInstanceId).list();

    System.out.println(" >>>>> Case executions: " + caseExecutions);
    
    for (CaseExecution caseExecution : caseExecutions)
    {
    	CaseExecutionEntity caseExecutionEntity0 = (CaseExecutionEntity)caseExecution;
    	System.out.println("Activity Name: " + caseExecutionEntity0.getActivityName());
    	System.out.println("Activity Id: " + caseExecutionEntity0.getActivityId());
    	System.out.println("Activity Type: " + caseExecutionEntity0.getActivityType());

    	List<CaseExecutionEntity> listCaseExecutionEntity = caseExecutionEntity0.getCaseExecutions();
	    System.out.println(" >>>>> Child case executions: " + listCaseExecutionEntity);
	    
	    for (CaseExecutionEntity caseExecutionEntity : listCaseExecutionEntity)
	    {
	    	System.out.println("Activity Name: " + caseExecutionEntity.getActivityName());
	    	System.out.println("Activity Id: " + caseExecutionEntity.getActivityId());
	    	System.out.println("Activity Type: " + caseExecutionEntity.getActivityType());
	    }
    }
    
    
    //disable milestone/humanTask/processTask
    for (CaseExecution caseExecution : caseExecutions)
    {
    	CaseExecutionEntity caseExecutionEntity = (CaseExecutionEntity)caseExecution;
    	String activityType = caseExecutionEntity.getActivityType(); 
    	if (activityType.equals("milestone") || activityType.equals("humanTask") || activityType.equals("processTask"))
    	{
    			try
    			{
    			    System.out.println(" >>>>> Disabling Activity Type: " + activityType);
    				caseExecutionEntity.disable();
    				
    				Thread.sleep(2000);
    				
    			    System.out.println(" >>>>> ReEnabling Activity Type: " + activityType);
    				caseExecutionEntity.reenable();
    			    System.out.println(" >>>>> Manual Start Activity Type: " + activityType);
    				caseExecutionEntity.manualStart();
    			}
    			catch (Exception e)
    			{
    				System.out.println(" >>>>> Exception for Activity Type: " + activityType);
    				e.printStackTrace();
    			}
    	}
    }	    

    //reactivate plan
    for (CaseExecution caseExecution : caseExecutions)
    {
    	CaseExecutionEntity caseExecutionEntity = (CaseExecutionEntity)caseExecution;
    	String activityType = caseExecutionEntity.getActivityType(); 
    	if (activityType.equals("casePlanModel"))
    	{
    			try
    			{
    				System.out.println(" >>>>> ReActivating Activity Type: " + activityType);
    				caseExecutionEntity.reactivate();
    			}
    			catch (Exception e)
    			{
    				System.out.println(" >>>>> Exception for Activity Type: " + activityType);
    				e.printStackTrace();
    			}
    	}
    }	    

}
}

Case Definition:

image

Can anyone please help? What is causing SQL errors? How to reactivate the case that is in state COMPLETED?


#2

Hi,

Your JavaDelegate implementation uses internal API methods heavily (i.e. methods defined in CaseExecutionEntity). This is not a good idea as they are not supposed to be used that way and may behave in an undefined manner, potentially resulting in errors like you see them. Instead, please rewrite your delegate using methods defined in CaseService and see if the problem persists.

Cheers,
Thorben


#3

Hi Thorben,

I had tried CaseService before trying CaseExecutionEntity. However, CaseService does not have an API to Re-Activate the completed case instance. There is an API to Re-Enable, however reenableCaseExecution(…) API throws an error saying this state transition is not possible. I am assuming reenableCaseExecution(…) API should be used for state transition from DISABLED to ENABLED. According to Camunda documentation https://docs.camunda.org/manual/7.7/reference/cmmn11/concepts/lifecycle/#case-instance-lifecycle DISABLED is not one of the valid states that case instance would have, so an exception from reenableCaseExecution(…) seem to be appropriate for requested state transition.

Could you please point out to the appropriate API to be used for case instance transition from COMPLETED to ACTIVE.


#4

I’m sorry, I didn’t check thoroughly enough before. Case instance re-activation is currently not implemented. I created two issues, see https://app.camunda.com/jira/browse/CAM-8690 and https://app.camunda.com/jira/browse/CAM-8691.

Please let us know if you would like to contribute this feature.

Cheers,
Thorben