AnsweredAssumed Answered

Terminating subprocess

Question asked by gthombare on Apr 21, 2011
I want to terminate subprocess on a user event so that all the assigned tasks of other users should also get killed. I have written custom java code for terminating subprocess.


My custom Java code looks like this.
————————————

public class TerminateProcess implements org.activiti.engine.delegate.JavaDelegate{

   Expression processInstanceId;
   @Override
   public void execute(DelegateExecution execution) throws Exception {   
      
      String strProcessInstanceId = processInstanceId.getValue(execution).toString();
      ProcessEngine pe = ProcessEngines.getDefaultProcessEngine();
      RuntimeService rs = pe.getRuntimeService();
      execution.removeVariablesLocal();
      rs.deleteProcessInstance(strProcessInstanceId, "Deleting SubProcess");
      
   }

}



subprocess is getting terminated but i am getting below exception. Please let me how should i handle this situation.

————————————————————————————————————

SEVERE: Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`activiti/ACT_RU_VARIABLE`, CONSTRAINT `ACT_FK_VAR_EXE` FOREIGN KEY (`EXECUTION_ID_`) REFERENCES `ACT_RU_EXECUTION` (`ID_`))
### The error may involve org.activiti.persistence.insertVariableInstance-Inline
### The error occurred while setting parameters
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`activiti/ACT_RU_VARIABLE`, CONSTRAINT `ACT_FK_VAR_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.insert(DefaultSqlSession.java:87)
        at org.activiti.engine.impl.db.DbSqlSession.flushInserts(DbSqlSession.java:392)
        at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:319)
        at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:134)
        at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:90)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
        at org.activiti.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:142)
        at org.activiti.rest.api.task.TaskOperationPut.executeWebScript(TaskOperationPut.java:56)
        at org.activiti.rest.util.ActivitiWebScript.executeImpl(ActivitiWebScript.java:68)
        at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64)
        at org.springframework.extensions.webscripts.PresentationContainer.executeScript(PresentationContainer.java:69)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:333)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:189)
        at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:662)

Outcomes