Manually update ByteArrayEntity in ACT_GE_BYTEARRAY

Let’s (theoretically) assume that I want to store custom json docs and don’t feel like setting up my own JPA persistence.
We have the ByteArrayEntity on which I can set id, name and bytes (json-string) - seems to be what I need. I also have code at hand (custom-batch-extension, taskpool-extension) where custom data is created and deleted via

CommandContext.getByteArrayManager().insertByteArray(...)

and

CommandContext.getByteArrayManager().deleteByteArrayById(id)

which works fine.

But: I now want to update the bytes content of a ByteArrayEntity … and this fails with:

ENGINE-03003 Inserting an entity with Id '...' and type 'class org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity' which is already marked with state 'PERSISTENT'

I tried deleting by id before inserting again, but that does not seem to work.

So my question is: What is the correct internal API to update a ByteArrayEntity?

Thanks

Hi Jan,

Calling ByteArrayEntity#setBytes is sufficient. The command context’s entity manager takes care of detecting changes in the entity and will then make a SQL UPDATE statement when the command finishes. Of course that requires that the byte array entity is tracked by the entity manager, i.e. it was selected or inserted via the db entity manager previously.

Cheers,
Thorben

edit: btw I assume you know this, but maybe for others who find this post: There is an API to store JSON documents in the engine (which under the hood will persist it as byte arrays), so usually it shouldn’t be needed to fiddle with internal API.

Thanks Thorben, will give it a try … yes should be managed …

UPDATE: it worked. Thanks!

The spin-API does not help me here … I do not deal with process-variables, I want to keep data from the last succesfull run of a daily instance for the next execution without relying on historic process variables. So each night I want to update the bytes of an Entity with the same fixed ID and query it from the process’ JavaDelegate.

1 Like