Thank you for your suggestion about pluggable variable persistence, I keep it in mind :)
But for now, I try with the process event listener approach and I tests your code with the same result.
I also try this, with the same result:
KieSession ksession = (KieSession) event.getKieRuntime();
WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) event.getProcessInstance();
Map<String, Object> variables = new HashMap<String, Object>(1);
variables.put(VAR_WF_CASE, wfCase);
ksession.execute(new SetProcessInstanceVariablesCommand(pi.getId(), variables));
So I try to set my variable in a ScriptTask at the begin of my process:
org.tests.model.WorkflowCase scriptCase = new org.tests.model.WorkflowCase();
scriptCase.setCaseId("case-id");
scriptCase.setCaseOrigin("case origin");
scriptCase.setServiceLevel("level");
kcontext.setVariable("wfCase", scriptCase);
Each time the variable wfCase is null.
The org.tests.model.WorkflowCase class is a POJO. jBPM can persist it in process variable ?
Regards,
Jérôme.