processDefinition = (ClientProcessDefinition) repositorySession.findProcessDefinitionByKey(processDefinitionKey);
if (processDefinition==null) {
throw new JbpmException("no process definition with key "+processDefinitionKey);
}
ClientProcessInstance processInstance = processDefinition.createProcessInstance(executionKey);
processInstance.setVariables(variables);
processInstance.start();
if (!processInstance.isEnded()) {
Session session = Environment.getFromCurrent(Session.class);
session.save(processInstance);
}
return processInstance;