Referential Integrity error when completing a task from my JUnit H2 test

595 views
Skip to first unread message

Alfonso Mateos Alarcón

unread,
Oct 8, 2014, 9:59:06 AM10/8/14
to camunda-...@googlegroups.com
Hi guys,

I get this error when I complete a task from my tests (in-memory, H2 db, extending ProcessEngineTestCase). Could you give me any hint on what's going on?
It's just one method failing, the rest of them they pass the test.

Thanks in advance :-)

Caused by: org.apache.ibatis.exceptions.PersistenceException: 

### Error updating database.  Cause: org.h2.jdbc.JdbcSQLException: Violación de una restricción de Integridad Referencial: "ACT_FK_VAR_BYTEARRAY: PUBLIC.ACT_RU_VARIABLE FOREIGN KEY(BYTEARRAY_ID_) REFERENCES PUBLIC.ACT_GE_BYTEARRAY(ID_) ('208')"

Referential integrity constraint violation: "ACT_FK_VAR_BYTEARRAY: PUBLIC.ACT_RU_VARIABLE FOREIGN KEY(BYTEARRAY_ID_) REFERENCES PUBLIC.ACT_GE_BYTEARRAY(ID_) ('208')"; SQL statement:

delete from ACT_GE_BYTEARRAY where ID_ = ? [23503-174]

### 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: Violación de una restricción de Integridad Referencial: "ACT_FK_VAR_BYTEARRAY: PUBLIC.ACT_RU_VARIABLE FOREIGN KEY(BYTEARRAY_ID_) REFERENCES PUBLIC.ACT_GE_BYTEARRAY(ID_) ('208')"

Referential integrity constraint violation: "ACT_FK_VAR_BYTEARRAY: PUBLIC.ACT_RU_VARIABLE FOREIGN KEY(BYTEARRAY_ID_) REFERENCES PUBLIC.ACT_GE_BYTEARRAY(ID_) ('208')"; SQL statement:

delete from ACT_GE_BYTEARRAY where ID_ = ? [23503-174]

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)

at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:147)

at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:158)

at org.camunda.bpm.engine.impl.db.DbSqlSession$BulkDeleteOperation.execute(DbSqlSession.java:189)

at org.camunda.bpm.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:723)

at org.camunda.bpm.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:490)

at org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:196)

at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:126)

... 29 more

Alfonso Mateos Alarcón

unread,
Oct 8, 2014, 11:12:13 AM10/8/14
to camunda-...@googlegroups.com

By the way, this is the piece of process that is being tested (the path which points downwards to cancel the process):


thorben....@camunda.com

unread,
Oct 8, 2014, 12:48:39 PM10/8/14
to camunda-...@googlegroups.com
Hi Alfonso,

what is going on is that a byte array is attempted to be deleted while there is still a variable in the database referencing it. Variables that implement the interface java.io.Serializable are persisted as byte arrays to the database. In this case, they are stored in the table ACT_GE_BYTEARRAY.

The harder question is why this is going on and I can hardly tell you why. Could you please post the entire stack trace, or even better create an isolated unit test that I can run to reproduce the problem?

Thanks and best regards,
Thorben

Alfonso Mateos Alarcón

unread,
Oct 9, 2014, 4:32:42 AM10/9/14
to camunda-...@googlegroups.com
Hi Thorben,

Thanks a lot, you gave me the hint to solve this issue ;-)
I was using a DataAccessor to access my instance variables in a strongly-typed way. Also, I tried to work this way:
- In order to check if a variable exists, I used (myAdapter.getMyVariable() == null). It would cover both the cases where the variable exists or is null.
- In order to remove a variable, I just executed a setMyVariable(null), and that caused the error when I did so witn a Dto (which is serializable) variable accessor.

I solved this by modifying the setVariable method inside MapProcessVariableAdapter, so that it removes it when I try to set a null value:

    @Override

    public <T extends Serializable> void setVariable(final String name, final T value) {

        if (value != null) {

            variables.put(name, value);

        } else {

            variables.remove(name);

        }

    }


Thanks a lot, Thorben ;-)

Reply all
Reply to author
Forward
0 new messages