AnsweredAssumed Answered

Getting error on transient variable usage in Activiti

Question asked by mhmtgk on Jun 5, 2017
Latest reply on Jun 7, 2017 by bassam.al-sarori

Hi All,

 

I am a bit new in Activiti engine. And decided to design a process that uses database queries at some points in service tasks. My aim is to rollback whole process if there is an error at the end of the process. Also I am not using spring because Activiti DB is not at the same side with the application. I use postgresql JDBC to submit external DB queries.

 

My main problem is Activiti gives error on the usage of transient variables. My process is like Start->Service Task 1 -> ServiceTask 2 -> End

 

 

<process id="transactionalTest" name="Transactional Test" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<endEvent id="endevent1" name="End"></endEvent>
<serviceTask id="servicetask1" name="Open Connection" activiti:class="dbfunctions.OpenConnection"></serviceTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<serviceTask id="servicetask2" name="Close Connection" activiti:class="dbfunctions.CloseConnection"></serviceTask>
<sequenceFlow id="flow8" sourceRef="servicetask2" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow9" sourceRef="servicetask1" targetRef="servicetask2"></sequenceFlow>
</process>

 

OpenConnection;

public void execute(DelegateExecution execution) {

Connection conn = null;
Statement stmt = null;

try {
conn = DriverManager.getConnection(DB_URL, USER, PASS);
} catch (Exception e) {
e.printStackTrace();
}

execution.setTransientVariable("conn",conn);
}

 

CloseConnection;

public void notify(DelegateExecution execution) {

...
Connection conn = (Connection) execution.getTransientVariable("conn");

conn.close();
...

}

 

And getting this error;

 

org.activiti.engine.impl.interceptor.CommandContext logException
SEVERE: Error while closing command context
java.lang.ClassCastException: org.activiti.engine.impl.persistence.entity.TransientVariableInstance cannot be cast to org.activiti.engine.impl.persistence.entity.VariableInstanceEntity
at org.activiti.engine.impl.persistence.entity.ExecutionEntityManagerImpl.deleteDataForExecution(ExecutionEntityManagerImpl.java:569)
at org.activiti.engine.impl.persistence.entity.ExecutionEntityManagerImpl.deleteExecutionAndRelatedData(ExecutionEntityManagerImpl.java:422)
at org.activiti.engine.impl.persistence.entity.ExecutionEntityManagerImpl.deleteProcessInstanceExecutionEntity(ExecutionEntityManagerImpl.java:455)
at org.activiti.engine.impl.agenda.EndExecutionOperation.handleProcessInstanceExecution(EndExecutionOperation.java:81)
at org.activiti.engine.impl.agenda.EndExecutionOperation.handleRegularExecution(EndExecutionOperation.java:166)
at org.activiti.engine.impl.agenda.EndExecutionOperation.run(EndExecutionOperation.java:48)
at org.activiti.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:73)
at org.activiti.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:57)
at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:42)
at org.activiti.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:48)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:63)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:29)
at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:44)
at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:39)
at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceByKey(RuntimeServiceImpl.java:82)
at org.activiti.designer.test.ProcessTestAnalogKTVAbonelikIptal.startProcess(ProcessTest.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.activiti.engine.test.ActivitiRule$1.evaluate(ActivitiRule.java:116)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 

 

How can I solve this error?

Outcomes