Are variables automatically saved in the process data?

Hello,

assume, I’ve have a complex object (with subobjects and nested fields) as one of the process variables.

Now, in a JavaDelegate, I extract this object (via execution.getVariable()), change some fields in it (possibly in nested objects) and then do nothing, i.e. I do not call execution.setVariable().

Assume also that the next activity in the process has the attribute “Async Before” set, i.e. it will be executed in another job/transcation.

What is the expected behaviour? Can I expect that the changed object will be automatically saved in the DB so that the next activity sees the changes? Or do I have to explicitly call setVariable() for this?

Another question to the same topic: What should happen if I do not change the object but call setVariable()? Will a new “variable changed” entry be created? Or will the engine notice that no changes have taken place (e.g. by comparing the serialized object) and make no entry?

If you don’t use execution.setVariable() the engine will not store any changes to the variables.
With regards to your second question - i’m pretty sure that if the variable has not changed there will not be any variable update added. But i haven’t tried it myself.

i’m pretty sure that if the variable has not changed there will not be any variable update added.

This is interesting (I’ll check). How would the engine find out there are no changes? Using equals? But then, if the class does not implement the equals method, the object will never be saved, even with an explicit call to setVariable (because the reference has not changed, and the default implementation of the equals method compares references).

Hence, the engine would have to check whether the serialization of the object has changed. But then, the engine can automatically detect object changes and save the object even without a call to setVariable.

Update: Because of the existence of the Issue CAM-3442, I assume that variables should be saved even without an explicit call to setVariable.

I see, i wasn’t taking into account that we were talking about objects. Seems like you’re correct. If an object is changed, it is indeed persisted.

Yes. I still have to conduct some experiments. The fact that the issue was not rejected is an indication that the objects should be saved. I wonder how the cahnges are detected. IMO, the only way is to serialize the object and to compare the value with the previously saved one. Because one can’t rely on the correct implementation of equals.