Hi,
In an asynchronous task I’m doing 3 REST calls to another system in sequence. (It tries to create 3 entities in the other system)
When the second or last call fails, I do not want to do the other calls again, so I tried storing the newly fetched variables in the engine afterwards by overwriting the existing marshalled JSON variable.
Example;
selectedUser = client.saveUser(selectedCompany.getId(), selectedUser);
execution.setVariable(VariableConstants.SELECTED_USER, selectedUser);
Unfortunately these setVariable actions are part of the transaction.
I tried following solution which creates a new tx to set the variable in but that resulted in a db exception. (Something that I cannot delete the previous bytearray value without deleting the variable linked to it.)
User finalSelectedUser = selectedUser;
processEngineConfiguration.getCommandExecutorTxRequiresNew().execute((Command<Void>) commandContext -> {
execution.setVariable(VariableConstants.SELECTED_USER, finalSelectedUser);
return null;
});
17:26:00,620 ERROR [org.camunda.bpm.engine.context] (pool-7-thread-7) ENGINE-16004 Exception while closing command context: ENGINE-03004 Exception while executing Database Operation ‘DELETE_BULK deleteByteArrayNoRevisionCheck 86be3d78-41fb-11e6-b231-ac87a3204ca5’ with message ’
Error updating database. Cause: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: “ACT_FK_VAR_BYTEARRAY: PUBLIC.ACT_RU_VARIABLE FOREIGN KEY(BYTEARRAY_ID_) REFERENCES PUBLIC.ACT_GE_BYTEARRAY(ID_) (‘86be3d78-41fb-11e6-b231-ac87a3204ca5’)”; SQL statement:
delete from ACT_GE_BYTEARRAY where ID_ = ? [23503-168]
The error may involve org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.deleteByteArrayNoRevisionCheck-Inline
The error occurred while setting parameters
SQL: delete from ACT_GE_BYTEARRAY where ID_ = ?
Cause: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: “ACT_FK_VAR_BYTEARRAY: PUBLIC.ACT_RU_VARIABLE FOREIGN KEY(BYTEARRAY_ID_) REFERENCES PUBLIC.ACT_GE_BYTEARRAY(ID_) (‘86be3d78-41fb-11e6-b231-ac87a3204ca5’)”; SQL statement:
delete from ACT_GE_BYTEARRAY where ID_ = ? [23503-168]'. Flush summary:
[
INSERT HistoricVariableUpdateEventEntity[9ce32fbb-41fb-11e6-b231-ac87a3204ca5]
INSERT ByteArrayEntity[9ce32fb9-41fb-11e6-b231-ac87a3204ca5]
INSERT ByteArrayEntity[9ce32fba-41fb-11e6-b231-ac87a3204ca5]
INSERT ByteArrayEntity[9ce356cc-41fb-11e6-b231-ac87a3204ca5]
DELETE_BULK deleteByteArrayNoRevisionCheck 86be3d78-41fb-11e6-b231-ac87a3204ca5
DELETE_BULK deleteByteArrayNoRevisionCheck 86be3d7b-41fb-11e6-b231-ac87a3204ca5
UPDATE HistoricVariableInstanceEntity[86b53d71-41fb-11e6-b231-ac87a3204ca5]
]: org.camunda.bpm.engine.ProcessEngineException: ENGINE-03004 Exception while executing Database Operation ‘DELETE_BULK deleteByteArrayNoRevisionCheck 86be3d78-41fb-11e6-b231-ac87a3204ca5’ with message ’Error updating database. Cause: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: “ACT_FK_VAR_BYTEARRAY: PUBLIC.ACT_RU_VARIABLE FOREIGN KEY(BYTEARRAY_ID_) REFERENCES PUBLIC.ACT_GE_BYTEARRAY(ID_) (‘86be3d78-41fb-11e6-b231-ac87a3204ca5’)”; SQL statement:
delete from ACT_GE_BYTEARRAY where ID_ = ? [23503-168]
The error may involve org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity.deleteByteArrayNoRevisionCheck-Inline
The error occurred while setting parameters
SQL: delete from ACT_GE_BYTEARRAY where ID_ = ?
Cause: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: “ACT_FK_VAR_BYTEARRAY: PUBLIC.ACT_RU_VARIABLE FOREIGN KEY(BYTEARRAY_ID_) REFERENCES PUBLIC.ACT_GE_BYTEARRAY(ID_) (‘86be3d78-41fb-11e6-b231-ac87a3204ca5’)”; SQL statement:
delete from ACT_GE_BYTEARRAY where ID_ = ? [23503-168]'. Flush summary:
[
INSERT HistoricVariableUpdateEventEntity[9ce32fbb-41fb-11e6-b231-ac87a3204ca5]
INSERT ByteArrayEntity[9ce32fb9-41fb-11e6-b231-ac87a3204ca5]
INSERT ByteArrayEntity[9ce32fba-41fb-11e6-b231-ac87a3204ca5]
INSERT ByteArrayEntity[9ce356cc-41fb-11e6-b231-ac87a3204ca5]
DELETE_BULK deleteByteArrayNoRevisionCheck 86be3d78-41fb-11e6-b231-ac87a3204ca5
DELETE_BULK deleteByteArrayNoRevisionCheck 86be3d7b-41fb-11e6-b231-ac87a3204ca5
UPDATE HistoricVariableInstanceEntity[86b53d71-41fb-11e6-b231-ac87a3204ca5]
]
Second thing I tried was to;
- Delete existing variable
- Create new variable with same name as previous
But this gives me another db exception;
08:50:17,958 ERROR [org.camunda.bpm.engine.context] (pool-7-thread-3) ENGINE-16004 Exception while closing command context: ENGINE-03004 Exception while executing Database Operation 'INSERT VariableInstanceEntity[bc08f3b2-427c-11e6-ac80-ac87a3204ca5]' with message '
### Error updating database. Cause: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "ACT_UNIQ_VARIABLE_INDEX_C ON PUBLIC.ACT_RU_VARIABLE(VAR_SCOPE_, NAME_)"; SQL statement:
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
) [23505-168]
### 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 )