JBoss Community

How to setVariable after JPAKnowledgeService.loadStatefulKnowledgeSession

created by Jack Q tao in jBPM - View the full discussion

Hi all,

 

I write some code to change variables of process  , but it can't work .

The error info:

    

java.lang.NullPointerException

          at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:67)

          at org.jbpm.process.instance.impl.ProcessInstanceImpl.getContextInstance(ProcessInstanceImpl.java:127)

          at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setVariable(WorkflowProcessInstanceImpl.java:237)

 

 

  My code :

 

    

 

 

                    KnowledgeBase kbase = createKnowledgeBase();

                    StatefulKnowledgeSession ksession =JPAKnowledgeService.loadStatefulKnowledgeSession(jbpm.getSessionId(), kbase, null, getEnv() );

                    CommanWSHumanTaskHandler humanTaskHandler = new CommanWSHumanTaskHandler(ksession);

                    humanTaskHandler.setClient(taskClientWrapper.getTaskClient());

                    humanTaskHandler.setSessionId(ksession.getId());

                    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);

                    humanTaskHandler.connect();

 

                    ProcessInstance pi = ksession.getProcessInstance(jbpm.getProcessId());

                    Boolean isSign = (Boolean) ((WorkflowProcessInstance)pi).getVariable("isSign");

                    List<String> list = (List<String>) ((WorkflowProcessInstance)pi).getVariable("signers");    //  isSign and list   are not null.

 

                    ((WorkflowProcessInstance)pi).setVariable("isSign", true);        // throws exception

                    ((WorkflowProcessInstance)pi).setVariable("signers", signers);

 

                    ksession.insert(pi);

 

 

I don't understand why.   and How to fix it.

Reply to this message by going to Community

Start a new discussion in jBPM at Community