I am having a multi instance user task MT inside an embedded sub process. The multi instance user task MT has task listener set on completion of task. The listener evaluates a condition and if true triggers the boundary signal event. The boundary signal event moves the flow to another user task UT inside the same sub process.
In order to signal UT, I use the following snippet in my on completion task listener of MT. It is executed only when a certain condition evaluates to true.
Lets say that the multi instance loops 5 times and the condition evaluates to true at 2nd, 4th and 5th instance. The MT task instances are completed but UT is not created or spawned though at 2nd and 4th instance. During execution of onComplete listener of 5th instance task, UT is again not created and the MT task instance rolls backs with following exception.
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table "act_ru_execution" violates foreign key constraint "act_fk_var_exe" on table "act_ru_variable"
Detail: Key (id_)=(695101) is still referenced from table "act_ru_variable".
### The error may involve org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl.deleteExecution-Inline
### The error occurred while setting parameters
### SQL: delete from ACT_RU_EXECUTION where ID_ = ? and REV_ = ?
### Cause: org.postgresql.util.PSQLException: ERROR: update or delete on table "act_ru_execution" violates foreign key constraint "act_fk_var_exe" on table "act_ru_variable"
Detail: Key (id_)=(695101) is still referenced from table "act_ru_variable".
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:213)
...
...
I am failing to debug why the boundary signal event is not being triggered and why the last instance of multi instance user task raises exception while executing its onComplete task listener.
If I sum it up in a few lines, the problem is that the on complete task listener on a multiinstance user task inside a subprocess doesn’t works for the last iteration (and rollbacks). I have tried with a dummy on complete task listener (method signature with no body) too but it also throws the same previous exception on last iteration.
If I remove the on complete task listener, it works fine. But, in my case an on complete task listener is must to have.
I moved away from using boundary signal event to event subprocess.
The problem was with duplicate name variables being stored in ACT_RU_VARIABLE. Renaming duplicates fixed the problem. A issue still is that if I complete like one of the instance of MT as soon as it is created (or may be a delay of 3-5s), the event subprocess signal is fired but the UT inside event subprocess is not created. Delaying completion of further instances also act the same.
If I complete the first MT instance task within a delay of say 15s+, it works fine then for all MTs.
and it all works great now. I can complete any of the MT task at the very instant it is created and the signal triggers the UT task at that very instant if the condition set evaluates to true.
I din’t get why processInstance scope dint work flawlessly as my signal is restricted to the process instance. In my case, I have been triggering the event using that very process execution Id (subscribed to the signal) and hence the global scope isn’t a problem for me.
@martin.grofcik I created a stub using the mvn command, But, not sure how to add onComplete task listener within the test case itself. Is it possible using only the dependencies in stub pom.
If I create onComplete task listener as a separate class, injection of RuntimeService or TaskService fails.
The provided test passes with global scope: <signal id="signal_start_ut" name="Signal Start UT" flowable:scope="global"></signal>
but fails with processInstance scope. <signal id="signal_start_ut" name="Signal Start UT" flowable:scope="processInstance"></signal>