<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Can you open a JIRA for this, and we'll make sure it's done in the next
few weeks:<br>
<a class="moz-txt-link-freetext"
 href="https://jira.jboss.org/jira/browse/JBRULES">https://jira.jboss.org/jira/browse/JBRULES</a><br>
<br>
thanks<br>
<br>
Mark<br>
<br>
<a class="moz-txt-link-abbreviated" href="mailto:Alan.Gairey@tessella.com">Alan.Gairey@tessella.com</a> wrote:
<blockquote
 cite="mid:OFC024AD63.0AB2A2A9-ON802575EC.00593295-802575EC.005BCB22@tessella.co.uk"
 type="cite">
  <p><font face="sans-serif" size="2">I'm currently using Drools Flow
with
JPA session persistence enabled as described in section 5.1 of the User
Guide.</font>
  </p>
  <p><font face="sans-serif" size="2">As a process executes, session
information
is saved to the H2 database correctly.</font>
  </p>
  <p><font face="sans-serif" size="2">The problem comes if a process
only executes
part way through, and I then try to finish the process by recreating a
session using the code:</font>
  <br>
  <br>
  <tt><font size="2">// recreate the session from database using the
sessionId<br>
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession( sessionId,
kbase, null, env );</font></tt>
  </p>
  <p><font face="sans-serif" size="2">This gives me a
NullPointerException.</font>
  </p>
  <p><font face="sans-serif" size="2">Having looked into the Drools
Flow source
code, I think the problem is in the class
drools-persistence-jpa\src\main\java\org\drools\persistence\session\SingleSessionCommandService.java.</font>
  </p>
  <p><font face="sans-serif" size="2">The 4th constructor of this class
is
called as part of the loading of a knowledge session from the H2
database;
this in turn leads to the afterCompletion method of the inner class
SynchronizationImpl
being called. The final two lines of this method are:</font>
  <br>
  <br>
  <tt><font size="2">((JPAProcessInstanceManager)
((ReteooWorkingMemory)
session).getProcessInstanceManager()).clearProcessInstances();</font></tt>
  <br>
  <tt><font size="2">((JPAWorkItemManager) ((ReteooWorkingMemory)
session).getWorkItemManager()).clearWorkItems();</font></tt>
  </p>
  <p><font face="sans-serif" size="2">However, when called via the
route described
above, the session member variable of SingleSessionCommandService has
not
been set, thus causing the NullPointerException.</font>
  </p>
  <p><font face="sans-serif" size="2">(Interestingly, running the unit
tests
for drools-persistence-jpa does result in the NullPointerException
being
thrown multiple times, although the tests are still listed as having
passed.)</font>
  </p>
  <p><font face="sans-serif" size="2">I believe enclosing the above two
lines
as follows will fix the problem:</font>
  <br>
  <br>
  <tt><font size="2">if (session != null) {</font></tt>
  <br>
  <tt><font size="2">&nbsp; &nbsp; ((JPAProcessInstanceManager)
((ReteooWorkingMemory)
session).getProcessInstanceManager()).clearProcessInstances();</font></tt>
  <br>
  <tt><font size="2">&nbsp; &nbsp; ((JPAWorkItemManager) ((ReteooWorkingMemory)
session).getWorkItemManager()).clearWorkItems();</font></tt>
  <br>
  <tt><font size="2">}</font></tt>
  <br>
  <br>
  <font face="sans-serif" size="2">Also, in the 4th constructor of
SingleSessionCommandService,
after the session has been set, the following line needs to be added to
ensure the session id is the same as the session info id:</font>
  <br>
  <br>
  <tt><font size="2">((ReteooStatefulSession) this.session).setId(
this.sessionInfo.getId()
);</font></tt>
  </p>
  <p><font face="sans-serif" size="2">(This line is present at the end
of the
3rd constructor.)</font>
  </p>
  <p><font face="sans-serif" size="2">It would be great if this fix
could make
it into the Drools 5.1 release.</font>
  </p>
  <p><font face="sans-serif" size="2">Thanks.<br>
  <br>
  <br>
  <br>
  <br>
  <br>
  </font>
  </p>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
  </pre>
</blockquote>
<br>
</body>
</html>