<br><font size=2 face="sans-serif">Mark,</font>
<br>
<br><font size=2 face="sans-serif">Done: https://jira.jboss.org/jira/browse/JBRULES-2199
- thanks for the quick response.</font>
<br>
<br><font size=2 face="sans-serif">Regards,</font>
<br>
<br><font size=2 face="sans-serif">Alan<br>
</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Mark Proctor &lt;mproctor@codehaus.org&gt;</b>
</font>
<br><font size=1 face="sans-serif">Sent by:</font>
<br><font size=1 face="sans-serif">rules-users-bounces@lists.jboss.org</font>
<p><font size=1 face="sans-serif">08/07/2009 13:49</font>
<table border>
<tr valign=top>
<td bgcolor=white><font size=1 face="sans-serif">Please respond to<br>
Rules Users List &lt;rules-users@lists.jboss.org&gt;</font></table>
<br>
<td width=59%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">Rules Users List &lt;rules-users@lists.jboss.org&gt;</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re: [rules-users] Problem with JPA session
persistence in Drools &nbsp; &nbsp; &nbsp; &nbsp;Flow &nbsp; &nbsp;
&nbsp; &nbsp;(5.0.1)</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=3>Can you open a JIRA for this, and we'll make sure it's
done in the next few weeks:</font><font size=3 color=blue><u><br>
</u></font><a href=https://jira.jboss.org/jira/browse/JBRULES><font size=3 color=blue><u>https://jira.jboss.org/jira/browse/JBRULES</u></font></a><font size=3><br>
<br>
thanks<br>
<br>
Mark<br>
</font><font size=3 color=blue><u><br>
</u></font><a href=mailto:Alan.Gairey@tessella.com><font size=3 color=blue><u>Alan.Gairey@tessella.com</u></font></a><font size=3>
wrote: </font>
<p><font size=2 face="sans-serif">I'm currently using Drools Flow with
JPA session persistence enabled as described in section 5.1 of the User
Guide.</font><font size=3> </font>
<p><font size=2 face="sans-serif">As a process executes, session information
is saved to the H2 database correctly.</font><font size=3> </font>
<p><font size=2 face="sans-serif">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><font size=3> <br>
</font><tt><font size=2><br>
// recreate the session from database using the sessionId<br>
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession( sessionId,
kbase, null, env );</font></tt><font size=3> </font>
<p><font size=2 face="sans-serif">This gives me a NullPointerException.</font><font size=3>
</font>
<p><font size=2 face="sans-serif">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><font size=3>
</font>
<p><font size=2 face="sans-serif">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><font size=3>
<br>
</font><tt><font size=2><br>
((JPAProcessInstanceManager) ((ReteooWorkingMemory) session).getProcessInstanceManager()).clearProcessInstances();</font></tt><font size=3>
</font><tt><font size=2><br>
((JPAWorkItemManager) ((ReteooWorkingMemory) session).getWorkItemManager()).clearWorkItems();</font></tt><font size=3>
</font>
<p><font size=2 face="sans-serif">However, when called via the route described
above, the session member variable of SingleSessionCommandService has not
been set, thus causing the NullPointerException.</font><font size=3> </font>
<p><font size=2 face="sans-serif">(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><font size=3>
</font>
<p><font size=2 face="sans-serif">I believe enclosing the above two lines
as follows will fix the problem:</font><font size=3> <br>
</font><tt><font size=2><br>
if (session != null) {</font></tt><font size=3> </font><tt><font size=2><br>
 &nbsp; &nbsp;((JPAProcessInstanceManager) ((ReteooWorkingMemory) session).getProcessInstanceManager()).clearProcessInstances();</font></tt><font size=3>
</font><tt><font size=2><br>
 &nbsp; &nbsp;((JPAWorkItemManager) ((ReteooWorkingMemory) session).getWorkItemManager()).clearWorkItems();</font></tt><font size=3>
</font><tt><font size=2><br>
}</font></tt><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
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><font size=3> <br>
</font><tt><font size=2><br>
((ReteooStatefulSession) this.session).setId( this.sessionInfo.getId()
);</font></tt><font size=3> </font>
<p><font size=2 face="sans-serif">(This line is present at the end of the
3rd constructor.)</font><font size=3> </font>
<p><font size=2 face="sans-serif">It would be great if this fix could make
it into the Drools 5.1 release.</font><font size=3> </font>
<p><font size=2 face="sans-serif">Thanks.<br>
<br>
<br>
<br>
<br>
</font>
<p><tt><font size=3><br>
</font></tt>
<hr><tt><font size=3><br>
_______________________________________________<br>
rules-users mailing list<br>
</font></tt><a href="mailto:rules-users@lists.jboss.org"><tt><font size=3 color=blue><u>rules-users@lists.jboss.org</u></font></tt></a><tt><font size=3><br>
</font></tt><a href="https://lists.jboss.org/mailman/listinfo/rules-users"><tt><font size=3 color=blue><u>https://lists.jboss.org/mailman/listinfo/rules-users</u></font></tt></a><tt><font size=3><br>
 &nbsp;</font></tt>
<br><tt><font size=2>_______________________________________________<br>
rules-users mailing list<br>
rules-users@lists.jboss.org<br>
https://lists.jboss.org/mailman/listinfo/rules-users<br>
</font></tt>
<br><font size=2 face="sans-serif"><br>
<br>
<br>
<br>
<br>
<br>
</font>