cancel
Showing results for 
Search instead for 
Did you mean: 

does JavaDelegate executes inside a TX?

luisalves00
Champ in-the-making
Champ in-the-making
Got something like this:


<serviceTask id="servicetask4" name="UpdateState"         activiti:class="some.package.UpdateState">        </serviceTask>‍‍‍‍‍

public class UpdateState implements JavaDelegate {    public void execute(DelegateExecution execution) throws Exception {        …           //update process vars        execution.setVariable("approved", approved);        execution.setVariable("sent", pa.isSent());        getSomeJpa().edit(pa);        ….    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

if getSomeJpa().edit(pa); throws an exception will the execution variable be changed on the DB and the workflow go forward?

thanks in advance.
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
Yes, all code executed between two wait states (e.g.. process-start -> usertask or usertaks -> user task or signal -> end, …) is in a single transaction and IF there are no "async" steps in between. before an async step is executed, the transaction is committed and the next operation is queued as a job.

So if you have 2 service-tasks after each other, they'll be executed in the same transaction. If the second throws an exception, all stuff done in service-task1 will be rolled back as well. After this, the process is back in the state it was before the API call. In case of an exception when starting a new process-instance, there is no process started at all.