<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Problem terminating concurent executions that have active sub-processes [jBPM 4.3/4.4 + Oracle]
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/misieq">Michal Klimuk</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/562698#562698">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I have a process that contains a fork activity with two branches - one containing a sub-process and the other any type of node from which we can terminate the whole process directly. A simplified version for test purposes would be:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-xml">
<span class="jive-xml-tag">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
<span class="jive-xml-tag"><span>&lt;process name="p1"
&#160;&#160;&#160; schemaLocation="</span><a class="jive-link-external-small" href="http://jbpm.org/4.0/jpdl" target="_blank">http://jbpm.org/4.0/jpdl</a><span> </span><a class="jive-link-external-small" href="http://docs.jboss.org/jbpm/xsd/jpdl-4.0.xsd" target="_blank">http://docs.jboss.org/jbpm/xsd/jpdl-4.0.xsd</a><span>"
&#160;&#160;&#160; xmlns="</span><a class="jive-link-external-small" href="http://jbpm.org/4.0/jpdl" target="_blank">http://jbpm.org/4.0/jpdl</a><span>"&gt;</span></span>

&#160;&#160;&#160; <span class="jive-xml-tag">&lt;start g="143,27,80,40" name="start"&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition g="-54,-22" name="to fork1" to="fork1" /&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/start&gt;</span>

&#160;&#160;&#160; <span class="jive-xml-tag">&lt;fork g="143,117,48,48" name="fork1"&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition g="-38,-22" name="to p2" to="p2" /&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition g="34,-14" name="to state1" to="state1" /&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/fork&gt;</span>

&#160;&#160;&#160; <span class="jive-xml-tag">&lt;state g="199,214,108,52" name="state1"&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition to="join1" /&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition g="-11,-21" name="end" to="end2" /&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/state&gt;</span>

&#160;&#160;&#160; <span class="jive-xml-tag">&lt;sub-process g="18,227,92,52" name="p2" sub-process-key="p2"&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition to="join1" /&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/sub-process&gt;</span>

&#160;&#160;&#160; <span class="jive-xml-tag">&lt;join g="141,334,48,48" name="join1"&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition to="end" /&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/join&gt;</span>

&#160;&#160;&#160; <span class="jive-xml-tag">&lt;end-cancel g="405,217,92,102" name="end2" /&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;end g="141,446,80,40" name="end" /&gt;</span>

<span class="jive-xml-tag">&lt;/process&gt;</span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>When I run the process and try to signal node 'state1' to end the whole process I get a constraint violation :</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="color:red">
org.hibernate.exception.ConstraintViolationException: could not delete: <a class="jive-link-external-small" href="org.jbpm.pvm.internal.model.ExecutionImpl#10002">org.jbpm.pvm.internal.model.ExecutionImpl#10002</a>
&#160;&#160;&#160; at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
&#160;&#160;&#160; at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
&#160;&#160;&#160; at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2569)
&#160;&#160;&#160; at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2725)
&#160;&#160;&#160; at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:97)
&#160;&#160;&#160; at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
&#160;&#160;&#160; at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
&#160;&#160;&#160; at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)
&#160;&#160;&#160; at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
&#160;&#160;&#160; at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)
&#160;&#160;&#160; at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:996)
&#160;&#160;&#160; at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1141)
&#160;&#160;&#160; at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
&#160;&#160;&#160; at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:835)
&#160;&#160;&#160; at org.jbpm.pvm.internal.hibernate.DbSessionImpl.findProcessInstanceByIdIgnoreSuspended(DbSessionImpl.java:211)
&#160;&#160;&#160; at org.jbpm.pvm.internal.hibernate.DbSessionImpl.deleteProcessInstance(DbSessionImpl.java:251)
&#160;&#160;&#160; at org.jbpm.pvm.internal.model.ExecutionImpl.end(ExecutionImpl.java:382)
&#160;&#160;&#160; at org.jbpm.jpdl.internal.activity.EndActivity.execute(EndActivity.java:82)
&#160;&#160;&#160; at org.jbpm.jpdl.internal.activity.EndActivity.execute(EndActivity.java:45)
&#160;&#160;&#160; at org.jbpm.pvm.internal.model.op.ExecuteActivity.perform(ExecuteActivity.java:60)
&#160;&#160;&#160; at org.jbpm.pvm.internal.model.ExecutionImpl.performAtomicOperationSync(ExecutionImpl.java:656)
&#160;&#160;&#160; at org.jbpm.pvm.internal.model.ExecutionImpl.performAtomicOperation(ExecutionImpl.java:616)
&#160;&#160;&#160; at org.jbpm.pvm.internal.model.ExecutionImpl.signal(ExecutionImpl.java:417)
&#160;&#160;&#160; at org.jbpm.pvm.internal.cmd.SignalCmd.execute(SignalCmd.java:61)
&#160;&#160;&#160; at org.jbpm.pvm.internal.cmd.SignalCmd.execute(SignalCmd.java:35)
&#160;&#160;&#160; at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
&#160;&#160;&#160; at org.jbpm.pvm.internal.tx.SpringCommandCallback.doInTransaction(SpringCommandCallback.java:45)
&#160;&#160;&#160; at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
&#160;&#160;&#160; at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:55)
&#160;&#160;&#160; at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
&#160;&#160;&#160; at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
&#160;&#160;&#160; at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
&#160;&#160;&#160; at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.signalExecutionById(ExecutionServiceImpl.java:88)
&#160;&#160;&#160; at org.jbpm.test.SubprocessTest.testEndWithActiveSubprocesses(SubprocessTest.java:25)
&#160;&#160;&#160; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
&#160;&#160;&#160; at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
&#160;&#160;&#160; at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
&#160;&#160;&#160; at java.lang.reflect.Method.invoke(Method.java:597)
&#160;&#160;&#160; at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:160)
&#160;&#160;&#160; at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
&#160;&#160;&#160; at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
&#160;&#160;&#160; at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
&#160;&#160;&#160; at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
&#160;&#160;&#160; at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
&#160;&#160;&#160; at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
&#160;&#160;&#160; at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
&#160;&#160;&#160; at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
&#160;&#160;&#160; at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
&#160;&#160;&#160; at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
&#160;&#160;&#160; at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
&#160;&#160;&#160; at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
&#160;&#160;&#160; at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
&#160;&#160;&#160; at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
&#160;&#160;&#160; at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
&#160;&#160;&#160; at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
&#160;&#160;&#160; at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
&#160;&#160;&#160; at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused&#160; by: java.sql.SQLException: ORA-02292: violation de contrainte&#160; (BDOOA.FK_EXEC_SUPEREXEC) d'int&eacute;grit&eacute; - enregistrement fils existant
&#160;&#160;&#160; at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
&#160;&#160;&#160; at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
&#160;&#160;&#160; at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
&#160;&#160;&#160; at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
&#160;&#160;&#160; at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
&#160;&#160;&#160; at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:966)
&#160;&#160;&#160; at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1170)
&#160;&#160;&#160; at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
&#160;&#160;&#160; at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3423)
&#160;&#160;&#160; at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2551)
&#160;&#160;&#160; ... 54 more
</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I investigated the problem and I found out that it is due to the fact that we never try to terminate an existing sub-process from within the ExecutionImpl.end() method. It causes a delete of the parent execution row although it is still referenced by SUPEREXEC_ column of the sub-process.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I created a patch that works and that consists on adding the following code to ExecutionImpl.end(String state) (my code in the middle paragraph):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">
&#160;&#160; // end all child executions
&#160;&#160; // making a copy of the executions to prevent ConcurrentMoidificationException
&#160;&#160;&#160; List&lt;ExecutionImpl&gt; executionsToEnd = new ArrayList&lt;ExecutionImpl&gt;(executions);
&#160;&#160;&#160; for (ExecutionImpl child: executionsToEnd) {
&#160;&#160;&#160;&#160;&#160; child.end(state);
&#160;&#160;&#160; }

&#160;&#160;&#160; // terminates the sub-process if it exists
&#160;&#160;&#160; if(subProcessInstance != null) {
&#160;&#160;&#160; // to avoid the return signal (see superProcessExecution.signal() in the end(String state) method)
&#160;&#160;&#160;&#160;&#160;&#160;&#160; subProcessInstance.setSuperProcessExecution(null);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; subProcessInstance.end(state);
&#160;&#160;&#160; }

&#160;&#160;&#160; setState(state);
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I don't know if it is the right approach but it works pretty much fine. Do you think it's the right way to do it?</p><p>I created a jira where I join the patch and a test module.</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/562698#562698">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>