Pedro Gonçalves [
https://community.jboss.org/people/pgoncalves] created the discussion
"jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"
To view the discussion, visit:
https://community.jboss.org/message/745092#745092
--------------------------------------------------------------
I'm using jbpm5.3, with spring and hibernate.
In the method I use to start a process instance, if I use the kSession.dispose() it will
give me the error below, but if not, it will work well! (The application was just started,
so no kSessions used before, and the database was clean)
It is not supposed to call dispose() when kSession will not be used anymore (I have one
kSession per process instance).
When I call kSession.dispose() for the first time, I got the error:
java.lang.IllegalStateException: Illegal method call. This session was previously
disposed.
at
org.drools.reteoo.DisposedReteooWorkingMemory.getProcessRuntime(DisposedReteooWorkingMemory.java:270)
at
org.drools.impl.StatefulKnowledgeSessionImpl.getProcessRuntime(StatefulKnowledgeSessionImpl.java:874)
at
org.drools.persistence.SingleSessionCommandService$SynchronizationImpl.afterCompletion(SingleSessionCommandService.java:448)
at
org.drools.persistence.jta.JtaTransactionSynchronizationAdapter.afterCompletion(JtaTransactionSynchronizationAdapter.java:25)
at
bitronix.tm.BitronixTransaction.fireAfterCompletionEvent(BitronixTransaction.java:497)
at bitronix.tm.BitronixTransaction.rollback(BitronixTransaction.java:283)
at
bitronix.tm.BitronixTransactionManager.rollback(BitronixTransactionManager.java:129)
at
org.springframework.transaction.jta.JtaTransactionManager.doRollback(JtaTransactionManager.java:1037)
(......)
How I start the process instance:
public void startProcess(CoreData coreData, String definitionId) {
//Creating variables ...
(...)
//taskService is a spring bean
LocalTaskService localTaskService = new LocalTaskService(taskService);
//GetKSession with null will create a new kSession
StatefulKnowledgeSession kSession = getKSession(null, localTaskService);
JPAWorkingMemoryDbLogger jbpmLogger = new JPAWorkingMemoryDbLogger(kSession);
ProcessInstance processInstance = kSession.startProcess(definitionId, variables);
jbpmLogger.dispose();
//If I remove this kSession.dispose() it will work well, but will give a optimistic lock
error later....
kSession.dispose();
}
How I create the kSession:
public StatefulKnowledgeSession getKSession(Integer kSessionId, LocalTaskService
localTaskService) {
StatefulKnowledgeSession kSession;
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY,
entityManagerWorkflow.getEntityManagerFactory());
env.set(EnvironmentName.TRANSACTION_MANAGER,
TransactionManagerServices.getTransactionManager());
if (kSessionId == null) {
kSession =
JPAKnowledgeService.newStatefulKnowledgeSession(knowledgeBaseProvider.getKbase(), null,
env);
} else {
kSession = JPAKnowledgeService.loadStatefulKnowledgeSession(kSessionId,
knowledgeBaseProvider.getKbase(), null, env);
}
/*
* Adding Listner
* */
CustomProcessEventListener customProcessEventListener = new
CustomProcessEventListener();
kSession.addEventListener(customProcessEventListener);
/*
* Register WorkItemHandler
* */
GenericHTWorkItemHandler handler = new GenericHTWorkItemHandler(kSession);
handler.setClient(localTaskService);
handler.setLocal(true);
handler.setIpAddress("127.0.0.1");
handler.setPort(9123);
handler.connect();
kSession.getWorkItemManager().registerWorkItemHandler("Human Task",
handler);
return kSession;
}
Thanks
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/745092#745092]
Start a new discussion in jBPM at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]