cancel
Showing results for 
Search instead for 
Did you mean: 

Updating the database from JavaDelegate

rodiaz
Champ in-the-making
Champ in-the-making
Hi all,

I don't know if there is a way to do what I want…
I have an async service task for executing several commands configured by the user. For example: create new file, copy, or delete a file…
If one of the commands fails in execution I throw a exception, but when the task is restarted I need to know what commands were successful because I don want executing them again.
I tried to do this setting a variable with my command identifier in my DelegateExecution with boolean value. But I noticed that this variable is not really stored until the execution is ended. So, if the execution is interrupted I never has that variable.
So, I tried as well to set it calling a rest service from my JavaDelagate that make it through RuntimeService

runtimeService.setVariable(executionId, variableName, value);

Now I can see that the database is updated but when the service task execution ends I get the error

Exception in thread "pool-2-thread-3" org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-02292: restricci?n de integridad (IBAP8.ACT_FK_VAR_EXE) violada - registro secundario encontrado

And the thread continues alive…

There is a way to do what I want??

Thanks in advance
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
The transaction is only committed at the end of the command, indeed and variable-updates only flushed at the end of the command. You CANNOT later process state (e.g.. set a variable) from another transaction, when the process is flowing. So setting a variable in the process should be done on the delegate itself. This is the way activiti works. If you want to store stuff that doesn't play with the activiti-transactions (ie. is not rolled back when something goes wrong) you should use a separate db-table with separate transaction…