+++ This bug was initially created as a clone of Bug #1245616 +++ Description of problem: When PerProcessInstance strategy is used and GetProcessInstanceByCorrelationKeyCommand is sent to /execute endpoint via REST then following exception is raised: [org.drools.persistence.SingleSessionCommandService] (http-/127.0.0.1:8080-3) Could not commit session: java.lang.IllegalStateException: Invalid session was used for this context org.kie.internal.runtime.manager.context.ProcessInstanceIdContext@79f8494f Version-Release number of selected component (if applicable): 6.1.1 How reproducible: always Steps to Reproduce: 1. Start any process StartCorrelatedProcessCommand 2. Try to get this process with GetProcessInstanceByCorrelationKeyCommand Process definition can be the simplest one. I have used following exact commands (sent to /execute endpoint): https://gist.github.com/anonymous/36173d7009da03b46f55 Actual results: Exception is raised when GetProcessInstanceByCorrelationKeyCommand is used via REST with PerProcessInstance strategy Expected results: Corresponding process should be correctly returned when GetProcessInstanceByCorrelationKeyCommand is used via REST API Additional info: This may be caused by the fact, that behind the scenes the wrong context is used for obtaining the RuntimeEngine, i.e. maybe something like this: manager.getRuntimeEngine(ProcessInstanceIdContext.get()) while this one should be used instead: manager.getRuntimeEngine(CorrelationKeyContext.get(key)) when CorrelationKey related commands are used.
Backported to the 6.2.x branch. Commits: Commits for JBPM-4296 were also backported because they're very related to the fix and make the code more readable/maintainable. 6.2.x: https://github.com/droolsjbpm/droolsjbpm-knowledge/commit/4230bcc0 https://github.com/droolsjbpm/droolsjbpm-knowledge/commit/b0dc7854 https://github.com/droolsjbpm/drools/commit/062422ba https://github.com/droolsjbpm/drools/commit/2db85423 https://github.com/droolsjbpm/jbpm/commit/993a0eb2 https://github.com/droolsjbpm/jbpm/commit/38153481 https://github.com/droolsjbpm/droolsjbpm-integration/commit/8294481b https://github.com/droolsjbpm/droolsjbpm-integration/commit/026e37bb
Verified in BPM Suite 6.1.3.CR1