<font face="Default Sans Serif,Verdana,Arial,Helvetica,sans-serif"><div>Hi, </div><div><br></div><div>  We&#39;re running an application that uses Drools + JBPM 5 + Drools integration our set-up can be seen as: </div><div>

<br></div><div>  Some rule fires and creates a JBPM process ( a fact gets inserted into drools using &quot;kcontext.getKnowledgeRuntime().startProcess(&quot;testProcess&quot;)&quot;
 ). We have a problem with the persistence of this processes. 
Persistence is implemented with JPA and JTA. Our application runs with 
fireUntilHalt() and when a process is launched from the consequence of 
any of the rules the persistence of the process fails. If the 
application runs with fireAllRules(), the persistence works like a 
charm.</div><div>  </div><div>  The error shown is as follow:</div><div>  </div><div> 
 Exception in thread &quot;Thread-5&quot; Exception executing consequence for rule
 &quot;Run Process&quot; in com.sample: java.lang.NullPointerException</div><div><span style="white-space:pre-wrap">        </span>at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)</div>

<div><span style="white-space:pre-wrap">        </span>at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)</div><div><span style="white-space:pre-wrap">        </span>at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)</div>

<div><span style="white-space:pre-wrap">        </span>at org.drools.common.DefaultAgenda.fireUntilHalt(DefaultAgenda.java:1229)</div><div><span style="white-space:pre-wrap">        </span>at org.drools.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:754)</div>

<div><span style="white-space:pre-wrap">        </span>at org.drools.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:730)</div><div><span style="white-space:pre-wrap">        </span>at org.drools.command.runtime.rule.FireUntilHaltCommand$1.run(FireUntilHaltCommand.java:50)</div>

<div><span style="white-space:pre-wrap">        </span>at java.lang.Thread.run(Thread.java:662)</div><div>Caused by: java.lang.NullPointerException</div><div><span style="white-space:pre-wrap">        </span>at org.jbpm.persistence.processinstance.JPAProcessInstanceManager.addProcessInstance(JPAProcessInstanceManager.java:44)</div>

<div><span style="white-space:pre-wrap">        </span>at org.jbpm.process.instance.AbstractProcessInstanceFactory.createProcessInstance(AbstractProcessInstanceFactory.java:36)</div><div><span style="white-space:pre-wrap">        </span>at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:182)</div>

<div><span style="white-space:pre-wrap">        </span>at org.jbpm.process.instance.ProcessRuntimeImpl.createProcessInstance(ProcessRuntimeImpl.java:154)</div><div><span style="white-space:pre-wrap">        </span>at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:135)</div>

<div><span style="white-space:pre-wrap">        </span>at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:130)</div><div><span style="white-space:pre-wrap">        </span>at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1074)</div>

<div><span style="white-space:pre-wrap">        </span>at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:301)</div><div><span style="white-space:pre-wrap">        </span>at com.sample.Rule_Run_Process.defaultConsequence(Rule_Run_Process.java:9)</div>

<div><span style="white-space:pre-wrap">        </span>at com.sample.Rule_Run_ProcessDefaultConsequenceInvoker.evaluate(Unknown Source)</div><div><span style="white-space:pre-wrap">        </span>at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)</div>

<div><span style="white-space:pre-wrap">        </span>... 6 more</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>The problem is in this function:</div><div><span style="white-space:pre-wrap">        </span></div>

<div><span style="white-space:pre-wrap">        </span>public void addProcessInstance(ProcessInstance processInstance) {</div><div>        ProcessInstanceInfo processInstanceInfo = new ProcessInstanceInfo( processInstance, this.kruntime.getEnvironment() );</div>

<div>        ProcessPersistenceContext context </div><div>            = ((ProcessPersistenceContextManager) this.kruntime.getEnvironment()</div><div>                    .get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER ))</div>

<div>                    .getProcessPersistenceContext();</div><div>        // @PrePersist added to ProcessInstanceInfo because of this</div><div>        context.persist( processInstanceInfo );</div><div>        ((org.jbpm.process.instance.ProcessInstance) processInstance).setId( processInstanceInfo.getId() );</div>

<div>        processInstanceInfo.updateLastReadDate();</div><div>        internalAddProcessInstance(processInstance);</div><div>    }</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>We
 think after that persist sentence, the entity manager would have to run
 a flush sentence for the process instance is inserted into database and
 get the ID.</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>Greets.</div></font>