Getting SQL Integrity Constraint Violation Exception for CAMUNDA.ACT_UNIQ_VARIABLE

Hi Team,

Am getting the below SQLIntegrityConstraintViolationException:

<Sep 19, 2017 11:11:44 PM EDT> <INFO 2017-09-19 23:11:44,127 [[ACTIVE] ExecuteThread: ‘6’ for queue: ‘weblogic.kernel.Default (self-tuning)’] common-log - processName - SdnaInterface, processId - 6e2c0419-9db1-11e7-95e1-005056b11dbe, activityId - StartEvent_05xm77v, activityName - sareaSDNTopologyRequest ->
Sep 19, 2017 11:11:45 PM org.camunda.commons.logging.BaseLogger logError
SEVERE: ENGINE-16004 Exception while closing command context: ENGINE-03004 Exception while executing Database Operation ‘INSERT VariableInstanceEntity[6e1806c8-9db1-11e7-95e1-005056b11dbe]’ with message ’

Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (CAMUNDA.ACT_UNIQ_VARIABLE) violated

The error may involve org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance-Inline

The error occurred while setting parameters

SQL: insert into ACT_RU_VARIABLE ( ID_, TYPE_, NAME_, PROC_INST_ID_, EXECUTION_ID_, CASE_INST_ID_, CASE_EXECUTION_ID_, TASK_ID_, BYTEARRAY_ID_, DOUBLE_, LONG_, TEXT_, TEXT2_, VAR_SCOPE_, SEQUENCE_COUNTER_, IS_CONCURRENT_LOCAL_, TENANT_ID_, REV_ ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1 )

Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (CAMUNDA.ACT_UNIQ_VARIABLE) violated

'. Flush summary:
[
INSERT HistoricVariableInstanceEntity[6e1806c8-9db1-11e7-95e1-005056b11dbe]
INSERT HistoricVariableInstanceEntity[6e1806ca-9db1-11e7-95e1-005056b11dbe]
INSERT HistoricVariableInstanceEntity[6e1806cc-9db1-11e7-95e1-005056b11dbe]
INSERT HistoricVariableInstanceEntity[6e182dde-9db1-11e7-95e1-005056b11dbe]
INSERT HistoricVariableInstanceEntity[6e2b8ee3-9db1-11e7-95e1-005056b11dbe]

Please suggest how to overcome from this??

Thanks,
Sudhanshu

Hi @Sudhanshu_Sekhar,

this error can happen when one and the same variable is added to one process instance from two concurrent threads.

Can you post here you BPMN file, the one that is being processed while this error happens?

One possible reason is the use of static variables in the delegate class.

Please check your Java code.

Hope this helps,

Ingo

Thank you @Ingo_Richtsmeier, Sure I will check & update you on this.

–Sudhanshu

Hi! Can you explain what do you mean by static variables in delegate class? Are there any restrictions on static variables while working with camunda?
I have the same problem (but in postgreSQL) and I don’t know what to do with this.

org.camunda.bpm.engine.ProcessEngineException: ENGINE-03004 Exception while executing Database Operation 'INSERT VariableInstanceEntity[0c600a5f-
ad02-11e7-8cb9-00505682444b]' with message '
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "act_uniq_variable"
  Detail: Key (var_scope_, name_)=(a40d51e1-acf9-11e7-8cb9-00505682444b, sa_absent_ngris_uuid) already exists.
### The error may involve org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.insertVariableInstance-Inline
### The error occurred while setting parameters
### SQL: insert into ACT_RU_VARIABLE     (       ID_,       TYPE_,       NAME_,       PROC_INST_ID_,       EXECUTION_ID_,       CASE_INST_ID_,
   CASE_EXECUTION_ID_,       TASK_ID_,       BYTEARRAY_ID_,       DOUBLE_,       LONG_,       TEXT_,       TEXT2_,       VAR_SCOPE_,       SEQUENC
E_COUNTER_,       IS_CONCURRENT_LOCAL_,       REV_     )     values (       ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,
  ?,       ?,       ?,       ?,       ?,       ?,       ?,       ?,       1     )
### Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "act_uniq_variable"
  Detail: Key (var_scope_, name_)=(a40d51e1-acf9-11e7-8cb9-00505682444b, sa_absent_ngris_uuid) already exists.'. Flush summary:
 [
  INSERT HistoricVariableInstanceEntity[0c600a5f-ad02-11e7-8cb9-00505682444b]
  INSERT HistoricVariableInstanceEntity[0c600a61-ad02-11e7-8cb9-00505682444b]
  INSERT HistoricVariableInstanceEntity[0c603176-ad02-11e7-8cb9-00505682444b]
  INSERT HistoricJobLogEventEntity[0c6169fe-ad02-11e7-8cb9-00505682444b]

I have a lot of places where variables that are already existed in camunda process are set again but usually I don’t have any problem with this, they’re just rewritten. But now I have this error and I don’t understand why.

The baseline is: Any code that is called by the process engine must be thread-safe. If your classes use mutable static variables, this is not the case. In particular, if you hold instances of engine-managed objects (e.g. Execution, Task, etc.) in static variables, you get funny behavior.

One more point though: This particular constraint is violated whenever the same variable is created in the same scope (=> execution or task) twice in parallel. The second transaction will fail with this exception. Could this be the case here?

This is definitely not my case.

No, I tried to rerun it right now to be sure, all alone, and got this error again.

Are you able to extract a minimal test case that reproduces this? If yes, could you please share it via github?

I’ve tried to reproduce it in tests but I couldn’t. So I’ve just tried to rename this variable and it has worked! Then I renamed it back and the problem didn’t return. It was very strange until I’ve realized that there was one more thing that I’ve changed: I’ve deleted this code:
execution.removeVariable("sa_absent_ngris_uuid");
Which I’ve added in an attempt to resolve this issue. So it seems that initial problem was caused by something else but this code made it persistent.
Anyway for now the problem is resolved.