AnsweredAssumed Answered

Exception upon arriving to join parallel gateway

Question asked by jesseou on Apr 5, 2011
Latest reply on Apr 6, 2011 by jesseou
Im having this exception upon arriving at a join parallel gateway:
SEVERE: Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`sut`.`ACT_RU_TASK`, CONSTRAINT `ACT_FK_TASK_EXE` FOREIGN KEY (`EXECUTION_ID_`) REFERENCES `ACT_RU_EXECUTION` (`ID_`))
### The error may involve org.activiti.persistence.deleteExecution-Inline
### The error occurred while setting parameters
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`sut`.`ACT_RU_TASK`, CONSTRAINT `ACT_FK_TASK_EXE` FOREIGN KEY (`EXECUTION_ID_`) REFERENCES `ACT_RU_EXECUTION` (`ID_`))
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:100)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:111)
   at org.activiti.engine.impl.db.DbSqlSession$DeleteById.execute(DbSqlSession.java:124)
   at org.activiti.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:416)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:321)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:135)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:91)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:124)
   at com.softekpr.sut.InstallationProcessTest.testBundleOrderProcess(InstallationProcessTest.java:127)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
   at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:176)
   at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:189)
   at org.testng.internal.Invoker.invokeMethod(Invoker.java:666)
   at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846)
   at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
   at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
   at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
   at org.testng.TestRunner.runWorkers(TestRunner.java:1125)
   at org.testng.TestRunner.privateRun(TestRunner.java:749)
   at org.testng.TestRunner.run(TestRunner.java:600)
   at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
   at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
   at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
   at org.testng.SuiteRunner.run(SuiteRunner.java:223)
   at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
   at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
   at org.testng.TestNG.runSuitesSequentially(TestNG.java:1007)
   at org.testng.TestNG.runSuitesLocally(TestNG.java:932)
   at org.testng.TestNG.run(TestNG.java:868)
   at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:110)
   at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
   at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)
   at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:85)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`sut`.`ACT_RU_TASK`, CONSTRAINT `ACT_FK_TASK_EXE` FOREIGN KEY (`EXECUTION_ID_`) REFERENCES `ACT_RU_EXECUTION` (`ID_`))
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
   at com.mysql.jdbc.Util.getInstance(Util.java:384)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1960)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105)
   at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1367)
   at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)
   at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:22)
   at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:51)
   at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:29)
   at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:72)
   at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:43)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:98)

This is my process xml:
<process id="bundleOrder">
        <startEvent id="bundleOrderStart"/>
        <sequenceFlow sourceRef='bundleOrderStart' targetRef='bundleItemDistributionSubProcess'/>
        <subProcess id="bundleItemDistributionSubProcess">
            <multiInstanceLoopCharacteristics isSequential="false"
                                              activiti:collection="${orderBundle.bundleOrderItems}"
                                              activiti:elementVariable="bundleOrderItem"/>

            <startEvent id="subProcessStart"/>

            <sequenceFlow sourceRef='subProcessStart' targetRef='bundleItemDistribution'/>
            <userTask id="bundleItemDistribution"
                      name="dist-${bundleOrderItem.order.orderNumber}-${bundleOrderItem.id}"
                      activiti:candidateGroups="SERVICE_COORDINATOR"
                      activiti:elementVariable="bundleOrderItem"
                      activiti:resultVariable="bundleOrderItem">
                <documentation>
                    Assign order item ${loopCounter + 1} from bundle '${orderBundle.name}'
                </documentation>
            </userTask>

            <sequenceFlow sourceRef="bundleItemDistribution" targetRef="bundleItemConfiguration"/>
            <userTask id="bundleItemConfiguration"
                      name="config-${bundleOrderItem.order.orderNumber}-${bundleOrderItem.id}">
                <documentation>Configure order item</documentation>               
            </userTask>

            <sequenceFlow sourceRef="bundleItemConfiguration" targetRef="subProcessFinish"/>
            <endEvent id="subProcessFinish"/>
        </subProcess>

        <sequenceFlow sourceRef='bundleItemDistributionSubProcess' targetRef='join'/>
        <parallelGateway id="join"/>

        <sequenceFlow id="exceptionFlow" sourceRef="join" targetRef="bundleDispatching"/>
        <userTask id="bundleDispatching" activiti:assignee="SERVICE_DISPATCHER">
            <documentation>Dispatch bundle</documentation>           
        </userTask>

        <sequenceFlow sourceRef="bundleDispatching" targetRef="bundleOrderFinish"/>
        <endEvent id="bundleOrderFinish"/>
    </process>

I found that the error occurs while trying to initiate the "bundleDispatching" task, the task is created (in memory) but never persisted because of the exception.  The funny thing is that if I change the targetRef of the "exceptionFlow" to "bundleOrderFinish" the error never occurred. Any ideas will be much appreciated!

Outcomes