Hi Michal!
I have a similar process like you and your patch works great!
But when I tried to run a more complex process, I got the ConstraintViolationException again.
I took your processes p1 and p2 and added a process p3:
<?xml version="1.0" encoding="UTF-8"?>
<process name="p3"
schemaLocation="http://jbpm.org/4.0/jpdl http://docs.jboss.org/jbpm/xsd/jpdl-4.0.xsd"
xmlns="http://jbpm.org/4.0/jpdl">
<start g="143,27,80,40" name="start">
<transition g="-54,-22" name="to fork1" to="fork1" />
</start>
<fork g="143,117,48,48" name="fork1">
<transition g="-38,-22" name="to p2" to="p2" />
<transition g="34,-14" name="to p2 (2)" to="p2 (2)" />
</fork>
<sub-process g="18,227,92,52" name="p2" sub-process-key="p2">
<transition to="join1" />
</sub-process>
<sub-process g="18,227,92,52" name="p2 (2)" sub-process-key="p2 (2)">
<transition to="join1" />
</sub-process>
<join g="141,334,48,48" name="join1">
<transition to="end" />
</join>
<end g="141,446,80,40" name="end" />
</process>
The process p3 just call two concurrent subprocesses to p2. And I changed the subprocess in p1 from p2 to p3.
So process p1 calls p3 that calls p2 two times in concurrent patchs. p1 -> p3 -> (2x) p2
The ConstraintViolationException throws after ending the first p2 execution.
Do you know why?