No Session Found for Context n using Spring and PER_PROCESS_INSTANCE Runtime Strategy

362 views
Skip to first unread message

Tony Cattlin

unread,
Jun 1, 2017, 7:02:50 AM6/1/17
to jBPM Development
Hi, 

JBPM 6.3 running in eclipse and using Spring. When running unit tests I am getting the following exception:

message: org.kie.internal.runtime.manager.SessionNotFoundException: No session found for context 1
at org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager$PerProcessInstanceInitializer.initKieSession(PerProcessInstanceRuntimeManager.java:535)
at org.jbpm.runtime.manager.impl.RuntimeEngineImpl.getKieSession(RuntimeEngineImpl.java:70)
at com.test.WorkflowService.printAllProcessInstances(WorkflowService.java:78)...

the offending code is engine.getKieSession().getProcessInstances() in :

    private void printAllProcessInstances() {
        for (AcrProcessInstance pi : instances) {
            RuntimeEngine engine = workflowRuntime.getRuntimeEngine(pi.getId());
            if (engine == null) {
                LOGGER.error("printAllProcessInstances: Cannot initialise JBPM engine.");
                return;
            }

            for (ProcessInstance instance : engine.getKieSession().getProcessInstances()) {
                LOGGER.debug("INSTANCE:" + instance.getId() + ": PIID:" + pi.getId());
            }
        }
        
    }
    

workflowRuntime.getRuntimeEngine is as follows:

    public RuntimeEngine getRuntimeEngine(Long pid) {
        runtimeManager = (RuntimeManager)appContext.getBean("runtimeManager");
        RuntimeEngine engine;

        if (pid.equals(0L)) {
            engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());
        } else {
            return runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(pid));
        }
        
        return engine;
    }

and I use pid = 0 when starting the process.

Any ideas why I get the exception ?

cheers

Tony

Tony Cattlin

unread,
Jun 2, 2017, 4:55:42 AM6/2/17
to jBPM Development
Looking at it more, it seems that the runtime is retrieved ok but the session is null. If I retrieve immediately after the session.startProcess then it works fine. 

- Am I right in assuming that the session should remain with the runtime until the instance dies ?
- What would cause the runtime to be retrieved ok but the session to be null ?

There has been no process closed or aborted events from the listeners, just trace to say it is in a user task.

Any guidance or suggestions would be great, thanks

Tony

Maciej Swiderski

unread,
Jun 3, 2017, 9:18:22 AM6/3/17
to Tony Cattlin, jBPM Development
When using persistence getProcesInstances on ksession will always return empty list. Use audit service instead 

Maciej 
--
You received this message because you are subscribed to the Google Groups "jBPM Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-developme...@googlegroups.com.
To post to this group, send email to jbpm-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-development/8db53d57-ebe1-4cf0-9877-76dc26d88990%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tony Cattlin

unread,
Jun 4, 2017, 4:12:24 AM6/4/17
to Maciej Swiderski, jBPM Development
Thanks Maciej, however, my issue is that getKieSession is blank. PrintAllProcessInsrances below was a precursor to abortProcessInstance. If I can't get the process instance because the session is empty, how can I abort it ?

Maciej Swiderski

unread,
Jun 4, 2017, 11:24:39 AM6/4/17
to Tony Cattlin, jBPM Development
Tony,

This would mean that ksession was not stored in db yet somehow. In general, getRuntimeEngine method should fail with no context found - which I think will happen if you use not existing process instance id. 
Though this does not happen here so context is set but ksession is not. Do you get into that error before tx completed after you start new process instance?

Maciej 

Tony Cattlin

unread,
Jun 4, 2017, 1:25:00 PM6/4/17
to Maciej Swiderski, jBPM Development
Thanks Maciej, yes, that is exactly my issue. Context is retrieved but null session. 

The session is not null if I make this call in the same transaction as startProcess. It is afterwards that it becomes null. 
Reply all
Reply to author
Forward
0 new messages