Camunda Process instance: An exception occurred in the persistence layer and optimistic locking exception

Hello,
We have a workflow model to automate the file transformation process. After completion of a service task, we encountered a problem on completing that delegate class.(have mentioned below)

 ERROR [camundaTaskExecutor-3]: ENGINE-16004 Exception while closing command context: An exception occurred in the persistence layer. Please check the server logs for a detailed message and the entire exception stack trace.
org.camunda.bpm.engine.ProcessEngineException: An exception occurred in the persistence layer. Please check the server logs for a detailed message and the entire exception stack trace.
        at org.camunda.bpm.engine.impl.util.ExceptionUtil.wrapPersistenceException(ExceptionUtil.java:360)
        at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.flushDbOperationException(EnginePersistenceLogger.java:137)
        at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(DbEntityManager.java:364)
        at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:323)
        at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flush(DbEntityManager.java:295)
        at org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:272)
        at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:188)
        at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:119)
        at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:71)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
        at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:71)
        at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:70)
        at org.camunda.bpm.engine.impl.interceptor.CommandCounterInterceptor.execute(CommandCounterInterceptor.java:35)
        at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
        at org.camunda.bpm.engine.impl.interceptor.ExceptionCodeInterceptor.execute(ExceptionCodeInterceptor.java:55)
        at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:57)
        at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:110)
        at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:71)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.camunda.bpm.engine.ProcessEngineException: ENGINE-03004 Exception while executing Database Operation 'INSERT VariableInstanceEntity[282b65fe-279f-11ee-9afe-0242ac1e000d]' with message '
### Error flushing statements.  Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance (batch index #5) failed. 4 prior sub executor(s) completed successfully, but will be rolled back. Cause: java.sql.BatchUpdateException: Batch entry 0 insert into ACT_RU_VARIABLE
    (
      ID_,
      TYPE_,
      NAME_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      EXECUTION_ID_,
      CASE_INST_ID_,
      CASE_EXECUTION_ID_,
      TASK_ID_,
      BATCH_ID_,
      BYTEARRAY_ID_,
      DOUBLE_,
      LONG_,
      TEXT_,
      TEXT2_,
      VAR_SCOPE_,
      SEQUENCE_COUNTER_,
      IS_CONCURRENT_LOCAL_,
      TENANT_ID_,
      REV_
    )
    values (
      '282b65fe-279f-11ee-9afe-0242ac1e000d',
      'string',
      'ReviewResultReason',
      'Process_0ay6634:42:d0e05465-270b-11ee-ac88-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      '',
      '!emptyString!',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      1,
      'FALSE',
      NULL,
      1
    ) was aborted: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
### Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance (batch index #5) failed. 4 prior sub executor(s) completed successfully, but will be rolled back. Cause: java.sql.BatchUpdateException: Batch entry 0 insert into ACT_RU_VARIABLE
    (
      ID_,
      TYPE_,
      NAME_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      EXECUTION_ID_,
      CASE_INST_ID_,
      CASE_EXECUTION_ID_,
      TASK_ID_,
      BATCH_ID_,
      BYTEARRAY_ID_,
      DOUBLE_,
      LONG_,
      TEXT_,
      TEXT2_,
      VAR_SCOPE_,
      SEQUENCE_COUNTER_,
      IS_CONCURRENT_LOCAL_,
      TENANT_ID_,
      REV_
    )
    values (
      '282b65fe-279f-11ee-9afe-0242ac1e000d',
      'string',
      'ReviewResultReason',
      'Process_0ay6634:42:d0e05465-270b-11ee-ac88-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      '',
      '!emptyString!',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      1,
      'FALSE',
      NULL,
      1
    ) was aborted: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
org.postgresql.util.PSQLException: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".
org.postgresql.util.PSQLException: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".
'. Flush summary:
 [
  INSERT HistoricVariableInstanceEntity[282b65fe-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableInstanceEntity[282b8d11-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableInstanceEntity[2ea989d3-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableInstanceEntity[2ea989d5-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableInstanceEntity[2ea9b0e7-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricJobLogEventEntity[2eabd3cc-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricJobLogEventEntity[2eabfadd-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[282b8d10-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[282b8d12-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[2ea989d4-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[2ea989d6-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[2ea9b0e8-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[2ea9b0e9-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricActivityInstanceEventEntity[Activity_1vj1i5l:282b65fd-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricActivityInstanceEventEntity[Gateway_1lv9gnf:2eabacba-279f-11ee-9afe-0242ac1e000d]
  INSERT VariableInstanceEntity[282b65fe-279f-11ee-9afe-0242ac1e000d]
  INSERT VariableInstanceEntity[282b8d11-279f-11ee-9afe-0242ac1e000d]
  INSERT VariableInstanceEntity[2ea989d3-279f-11ee-9afe-0242ac1e000d]
  INSERT VariableInstanceEntity[2ea989d5-279f-11ee-9afe-0242ac1e000d]
  INSERT VariableInstanceEntity[2ea9b0e7-279f-11ee-9afe-0242ac1e000d]
  INSERT MessageEntity[2eabd3cb-279f-11ee-9afe-0242ac1e000d]
  DELETE MessageEntity[282ac9ba-279f-11ee-9afe-0242ac1e000d]
  UPDATE VariableInstanceEntity[281fa5e6-279f-11ee-9afe-0242ac1e000d]
  UPDATE ExecutionEntity[281fa5d2-279f-11ee-9afe-0242ac1e000d]
  UPDATE HistoricVariableInstanceEntity[281fa5e6-279f-11ee-9afe-0242ac1e000d]
]
        at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.flushDbOperationException(EnginePersistenceLogger.java:136)
        ... 19 common frames omitted
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error flushing statements.  Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance (batch index #5) failed. 4 prior sub executor(s) completed successfully, but will be rolled back.
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:254)
        at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.flushBatchOperations(DbSqlSession.java:443)
        at org.camunda.bpm.engine.impl.db.sql.BatchDbSqlSession.executeDbOperations(BatchDbSqlSession.java:73)
        at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(DbEntityManager.java:341)
        ... 18 common frames omitted
Caused by: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance (batch index #5) failed. 4 prior sub executor(s) completed successfully, but will be rolled back.
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
        at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:149)
        at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:129)
        at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:122)
        at org.apache.ibatis.executor.CachingExecutor.flushStatements(CachingExecutor.java:114)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:252)
        ... 21 common frames omitted
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into ACT_RU_VARIABLE
    (
      ID_,
      TYPE_,
      NAME_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      EXECUTION_ID_,
      CASE_INST_ID_,
      CASE_EXECUTION_ID_,
      TASK_ID_,
      BATCH_ID_,
      BYTEARRAY_ID_,
      DOUBLE_,
      LONG_,
      TEXT_,
      TEXT2_,
      VAR_SCOPE_,
      SEQUENCE_COUNTER_,
      IS_CONCURRENT_LOCAL_,
      TENANT_ID_,
      REV_
    )
    values (
      '282b65fe-279f-11ee-9afe-0242ac1e000d',
      'string',
      'ReviewResultReason',
      'Process_0ay6634:42:d0e05465-270b-11ee-ac88-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      '',
      '!emptyString!',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      1,
      'FALSE',
      NULL,
      1
    ) was aborted: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
        at org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:165)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2366)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:559)
        at org.postgresql.jdbc.PgStatement.internalExecuteBatch(PgStatement.java:887)
        at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:910)
        at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1649)
        at com.zaxxer.hikari.pool.ProxyStatement.executeBatch(ProxyStatement.java:127)
        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeBatch(HikariProxyPreparedStatement.java)
        at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:123)
        ... 25 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2675)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2365)
        ... 32 common frames omitted
2023-07-21 08:18:33,148 WARN  [camundaTaskExecutor-3]: ENGINE-14006 Exception while executing job 282ac9ba-279f-11ee-9afe-0242ac1e000d:
org.camunda.bpm.engine.ProcessEngineException: An exception occurred in the persistence layer. Please check the server logs for a detailed message and the entire exception stack trace.
        at org.camunda.bpm.engine.impl.util.ExceptionUtil.wrapPersistenceException(ExceptionUtil.java:360)
        at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.flushDbOperationException(EnginePersistenceLogger.java:137)
        at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(DbEntityManager.java:364)
        at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:323)
        at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flush(DbEntityManager.java:295)
        at org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:272)
        at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:188)
        at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:119)
        at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:71)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
        at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:71)
        at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:70)
        at org.camunda.bpm.engine.impl.interceptor.CommandCounterInterceptor.execute(CommandCounterInterceptor.java:35)
        at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
        at org.camunda.bpm.engine.impl.interceptor.ExceptionCodeInterceptor.execute(ExceptionCodeInterceptor.java:55)
        at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:57)
        at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:110)
        at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:71)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.camunda.bpm.engine.ProcessEngineException: ENGINE-03004 Exception while executing Database Operation 'INSERT VariableInstanceEntity[282b65fe-279f-11ee-9afe-0242ac1e000d]' with message '
### Error flushing statements.  Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance (batch index #5) failed. 4 prior sub executor(s) completed successfully, but will be rolled back. Cause: java.sql.BatchUpdateException: Batch entry 0 insert into ACT_RU_VARIABLE
    (
      ID_,
      TYPE_,
      NAME_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      EXECUTION_ID_,
      CASE_INST_ID_,
      CASE_EXECUTION_ID_,
      TASK_ID_,
      BATCH_ID_,
      BYTEARRAY_ID_,
      DOUBLE_,
      LONG_,
      TEXT_,
      TEXT2_,
      VAR_SCOPE_,
      SEQUENCE_COUNTER_,
      IS_CONCURRENT_LOCAL_,
      TENANT_ID_,
      REV_
    )
    values (
      '282b65fe-279f-11ee-9afe-0242ac1e000d',
      'string',
      'ReviewResultReason',
      'Process_0ay6634:42:d0e05465-270b-11ee-ac88-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      '',
      '!emptyString!',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      1,
      'FALSE',
      NULL,
      1
    ) was aborted: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
### Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance (batch index #5) failed. 4 prior sub executor(s) completed successfully, but will be rolled back. Cause: java.sql.BatchUpdateException: Batch entry 0 insert into ACT_RU_VARIABLE
    (
      ID_,
      TYPE_,
      NAME_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      EXECUTION_ID_,
      CASE_INST_ID_,
      CASE_EXECUTION_ID_,
      TASK_ID_,
      BATCH_ID_,
      BYTEARRAY_ID_,
      DOUBLE_,
      LONG_,
      TEXT_,
      TEXT2_,
      VAR_SCOPE_,
      SEQUENCE_COUNTER_,
      IS_CONCURRENT_LOCAL_,
      TENANT_ID_,
      REV_
    )
    values (
      '282b65fe-279f-11ee-9afe-0242ac1e000d',
      'string',
      'ReviewResultReason',
      'Process_0ay6634:42:d0e05465-270b-11ee-ac88-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      '',
      '!emptyString!',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      1,
      'FALSE',
      NULL,
      1
    ) was aborted: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
java.sql.BatchUpdateException: Batch entry 0 insert into ACT_RU_VARIABLE
    (
      ID_,
      TYPE_,
      NAME_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      EXECUTION_ID_,
      CASE_INST_ID_,
      CASE_EXECUTION_ID_,
      TASK_ID_,
      BATCH_ID_,
      BYTEARRAY_ID_,
      DOUBLE_,
      LONG_,
      TEXT_,
      TEXT2_,
      VAR_SCOPE_,
      SEQUENCE_COUNTER_,
      IS_CONCURRENT_LOCAL_,
      TENANT_ID_,
      REV_
    )
    values (
      '282b65fe-279f-11ee-9afe-0242ac1e000d',
      'string',
      'ReviewResultReason',
      'Process_0ay6634:42:d0e05465-270b-11ee-ac88-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      '',
      '!emptyString!',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      1,
      'FALSE',
      NULL,
      1
    ) was aborted: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
org.postgresql.util.PSQLException: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".
org.postgresql.util.PSQLException: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".
'. Flush summary:
 [
  INSERT HistoricVariableInstanceEntity[282b65fe-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableInstanceEntity[282b8d11-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableInstanceEntity[2ea989d3-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableInstanceEntity[2ea989d5-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableInstanceEntity[2ea9b0e7-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricJobLogEventEntity[2eabd3cc-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricJobLogEventEntity[2eabfadd-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[282b8d10-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[282b8d12-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[2ea989d4-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[2ea989d6-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[2ea9b0e8-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricVariableUpdateEventEntity[2ea9b0e9-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricActivityInstanceEventEntity[Activity_1vj1i5l:282b65fd-279f-11ee-9afe-0242ac1e000d]
  INSERT HistoricActivityInstanceEventEntity[Gateway_1lv9gnf:2eabacba-279f-11ee-9afe-0242ac1e000d]
  INSERT VariableInstanceEntity[282b65fe-279f-11ee-9afe-0242ac1e000d]
  INSERT VariableInstanceEntity[282b8d11-279f-11ee-9afe-0242ac1e000d]
  INSERT VariableInstanceEntity[2ea989d3-279f-11ee-9afe-0242ac1e000d]
  INSERT VariableInstanceEntity[2ea989d5-279f-11ee-9afe-0242ac1e000d]
  INSERT VariableInstanceEntity[2ea9b0e7-279f-11ee-9afe-0242ac1e000d]
  INSERT MessageEntity[2eabd3cb-279f-11ee-9afe-0242ac1e000d]
  DELETE MessageEntity[282ac9ba-279f-11ee-9afe-0242ac1e000d]
  UPDATE VariableInstanceEntity[281fa5e6-279f-11ee-9afe-0242ac1e000d]
  UPDATE ExecutionEntity[281fa5d2-279f-11ee-9afe-0242ac1e000d]
  UPDATE HistoricVariableInstanceEntity[281fa5e6-279f-11ee-9afe-0242ac1e000d]
]
        at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.flushDbOperationException(EnginePersistenceLogger.java:136)
        ... 19 common frames omitted
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error flushing statements.  Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance (batch index #5) failed. 4 prior sub executor(s) completed successfully, but will be rolled back. Cause: java.sql.BatchUpdateException: Batch entry 0 insert into ACT_RU_VARIABLE
    (
      ID_,
      TYPE_,
      NAME_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      EXECUTION_ID_,
      CASE_INST_ID_,
      CASE_EXECUTION_ID_,
      TASK_ID_,
      BATCH_ID_,
      BYTEARRAY_ID_,
      DOUBLE_,
      LONG_,
      TEXT_,
      TEXT2_,
      VAR_SCOPE_,
      SEQUENCE_COUNTER_,
      IS_CONCURRENT_LOCAL_,
      TENANT_ID_,
      REV_
    )
    values (
      '282b65fe-279f-11ee-9afe-0242ac1e000d',
      'string',
      'ReviewResultReason',
      'Process_0ay6634:42:d0e05465-270b-11ee-ac88-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      '',
      '!emptyString!',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      1,
      'FALSE',
      NULL,
      1
    ) was aborted: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
### Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance (batch index #5) failed. 4 prior sub executor(s) completed successfully, but will be rolled back. Cause: java.sql.BatchUpdateException: Batch entry 0 insert into ACT_RU_VARIABLE
    (
      ID_,
      TYPE_,
      NAME_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      EXECUTION_ID_,
      CASE_INST_ID_,
      CASE_EXECUTION_ID_,
      TASK_ID_,
      BATCH_ID_,
      BYTEARRAY_ID_,
      DOUBLE_,
      LONG_,
      TEXT_,
      TEXT2_,
      VAR_SCOPE_,
      SEQUENCE_COUNTER_,
      IS_CONCURRENT_LOCAL_,
      TENANT_ID_,
      REV_
    )
    values (
      '282b65fe-279f-11ee-9afe-0242ac1e000d',
      'string',
      'ReviewResultReason',
      'Process_0ay6634:42:d0e05465-270b-11ee-ac88-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      '',
      '!emptyString!',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      1,
      'FALSE',
      NULL,
      1
    ) was aborted: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:254)
        at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.flushBatchOperations(DbSqlSession.java:443)
        at org.camunda.bpm.engine.impl.db.sql.BatchDbSqlSession.executeDbOperations(BatchDbSqlSession.java:73)
        at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(DbEntityManager.java:341)
        ... 18 common frames omitted
Caused by: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance (batch index #5) failed. 4 prior sub executor(s) completed successfully, but will be rolled back. Cause: java.sql.BatchUpdateException: Batch entry 0 insert into ACT_RU_VARIABLE
    (
      ID_,
      TYPE_,
      NAME_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      EXECUTION_ID_,
      CASE_INST_ID_,
      CASE_EXECUTION_ID_,
      TASK_ID_,
      BATCH_ID_,
      BYTEARRAY_ID_,
      DOUBLE_,
      LONG_,
      TEXT_,
      TEXT2_,
      VAR_SCOPE_,
      SEQUENCE_COUNTER_,
      IS_CONCURRENT_LOCAL_,
      TENANT_ID_,
      REV_
    )
    values (
      '282b65fe-279f-11ee-9afe-0242ac1e000d',
      'string',
      'ReviewResultReason',
      'Process_0ay6634:42:d0e05465-270b-11ee-ac88-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      '',
      '!emptyString!',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      1,
      'FALSE',
      NULL,
      1
    ) was aborted: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
        at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:149)
        at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:129)
        at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:122)
        at org.apache.ibatis.executor.CachingExecutor.flushStatements(CachingExecutor.java:114)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:252)
        ... 21 common frames omitted
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into ACT_RU_VARIABLE
    (
      ID_,
      TYPE_,
      NAME_,
      PROC_DEF_ID_,
      PROC_INST_ID_,
      EXECUTION_ID_,
      CASE_INST_ID_,
      CASE_EXECUTION_ID_,
      TASK_ID_,
      BATCH_ID_,
      BYTEARRAY_ID_,
      DOUBLE_,
      LONG_,
      TEXT_,
      TEXT2_,
      VAR_SCOPE_,
      SEQUENCE_COUNTER_,
      IS_CONCURRENT_LOCAL_,
      TENANT_ID_,
      REV_
    )
    values (
      '282b65fe-279f-11ee-9afe-0242ac1e000d',
      'string',
      'ReviewResultReason',
      'Process_0ay6634:42:d0e05465-270b-11ee-ac88-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
      '',
      '!emptyString!',
      '281fa5d2-279f-11ee-9afe-0242ac1e000d',
      1,
      'FALSE',
      NULL,
      1
    ) was aborted: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".  Call getNextException to see other errors in the batch.
        at org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:165)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2366)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:559)
        at org.postgresql.jdbc.PgStatement.internalExecuteBatch(PgStatement.java:887)
        at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:910)
        at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1649)
        at com.zaxxer.hikari.pool.ProxyStatement.executeBatch(ProxyStatement.java:127)
        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeBatch(HikariProxyPreparedStatement.java)
        at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:123)
        ... 25 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "act_ru_variable" violates foreign key constraint "act_fk_var_exe"
  Detail: Key (execution_id_)=(281fa5d2-279f-11ee-9afe-0242ac1e000d) is not present in table "act_ru_execution".
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2675)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2365)
        ... 32 common frames omitted

ENGINE-14006 Exception while executing job <id>: OptimisticLockingException.

We will be creating and updating variables inside delegate classes of the workflow model. This happens randomly. We are not inserting any duplicate variables but still getting this error. Did anybody else faced the same issue? It will be very helpful if we could resolve this

Thanks in advance.

Spring Boot: 2.7.13
Camunda Version: 7.19.0
DBMS: PostgreSQL

HI, did u get a resolution for the above issue?