Getting OptimisticLockingException when retrieving the tasks

Hello everyone.

In the project we have faced with following issue:

We have registered our custom VariableSerializer for the encryption of variables:

  • We encrypt variable inside serializeToByteArray method before it has been inserted into database.
  • We decrypt the variable inside deserializeFromByteArray after it has been retrieved from the database.

However, sometimes when getting the list of tasks we are getting following exception:

2021-11-25 09:19:43.660 WARN 1 --- [nio-8088-exec-2] ExceptionHandler : org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of 'UPDATE VariableInstanceEntity[5726e384-4ce9-11ec-9eb7-bae974252298]' failed. Entity was updated by another transaction concurrently.

Would appreciate any hint why we are getting this exception, since this error started to appear after we implemented encryption.
Thanks in advance.