2 Replies Latest reply on Nov 21, 2011 1:04 AM by Jack Q tao

    How to setVariable after JPAKnowledgeService.loadStatefulKnowledgeSession

    Jack Q tao Newbie

      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.

        • 2. Re: How to setVariable after JPAKnowledgeService.loadStatefulKnowledgeSession
          Jack Q tao Newbie

          solve it.

           

          I set a uuid for every flow !

          and cached signers  by uuid .   cache.put(uuid ,List<String> signers);

          and cache.get(uuid) by script task.

           

          if(null == p || p.size()==0){

                               isSign = false;

                               signers = null;

                               kcontext.setVariable("isSign",false);

                              kcontext.setVariable("signers",null);

                     }else{

                                         isSign = true;

                                         signers = p;

                                         kcontext.setVariable("isSign",true);

                                        kcontext.setVariable("signers",p);

                                        JbpmCache.remove(uuid);

                     }

           

          1 of 1 people found this helpful