Yes you should update the fact. Using ksession.update() method.<br>Take a look at the insert method that returns the FactHandle that you need to use later in order to update the fact.<br>Cheers<br><br><div class="gmail_quote">
2011/7/10 Neelesh Deo Dani <span dir="ltr">&lt;<a href="mailto:neeleshdev@yahoo.co.in">neeleshdev@yahoo.co.in</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font:inherit" valign="top"><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">Hi,</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">
I&#39;m using drools expert. When I insert the User object again in the session, after modifying the member variable &#39;trades&#39; (details mentioned below) the rule doesn&#39;t get evaluated. It evaluate the rules only during the 1st insert. Is there a way to trigger the rule evaluation after every insert of the same object (when state is modified)?</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"><br></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"> I&#39;ve following declaration and rule.</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">
<font color="#B70000">------------</font></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"><span style="color:#b70000">declare</span> User </p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">    @timestamp(datetime) </p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">    name : String</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">    trades: Integer </p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000">end</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000"><br></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000">
</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#009700"><span style="color:#b70000">rule</span><span style="color:#000000"> </span>&quot;Trades&quot;<span style="color:#000000"> </span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000">when<span style="color:#000000"> </span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">    $u:User(trades &gt;= 3)</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000">then</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">    System.out.println(<span style="color:#009700">&quot;Trades &gt; 3 for &quot;</span>+ $u.getName());</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000">end<span style="color:#000000"> </span></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000"><span style="color:#000000">----------</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000"><span style="color:#000000">Following is the piece of code:</span></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000"><span style="color:#000000"><br>
</span></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000"><span style="color:#000000"></span></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">StatefulKnowledgeSession session = s.<span style="color:#2700ce">kbase</span>.newStatefulKnowledgeSession();</p>
<p></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000"><span style="color:#000000"></span></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">String[] names = <span style="color:#a10067">new</span> String[]{<span style="color:#5100ff">&quot;bob&quot;</span>, <span style="color:#5100ff">&quot;sam&quot;</span>, <span style="color:#5100ff">&quot;john&quot;</span>};</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">FactType userType = s.<span style="color:#2700ce">kbase</span>.getFactType(<span style="color:#5100ff">&quot;com.sample&quot;</span>, <span style="color:#5100ff">&quot;User&quot;</span> );</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"><br></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">Map&lt;String, Object&gt; name2user = <span style="color:#a10067">new</span> HashMap&lt;String, Object&gt;();</p>

<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"><span style="white-space:pre-wrap">                </span><span style="color:#a10067">for</span>( String name: names ){ </p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"><span style="white-space:pre-wrap">                        </span>Object u = userType.newInstance();</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"><span style="white-space:pre-wrap">                        </span>userType.set(u, <span style="color:#5100ff">&quot;name&quot;</span>, name);</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"><span style="white-space:pre-wrap">                        </span>name2user.put(name, u);</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"><span style="white-space:pre-wrap">                </span>}</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"><br></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">
</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">userType.set(name2user.get(<span style="color:#5100ff">&quot;bob&quot;</span>), <span style="color:#5100ff">&quot;trades&quot;</span>, 1);</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">
</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">session.insert(name2user.get(<span style="color:#5100ff">&quot;bob&quot;</span>));</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">
session.fireAllRules();</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"><br></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco"></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">
<span style="text-decoration:underline">userType</span>.set(name2user.get(<span style="color:#5100ff">&quot;bob&quot;</span>), <span style="color:#5100ff">&quot;trades&quot;</span>, 3);</p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco">
</p><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">session.insert(name2user.get(<span style="color:rgb(81, 0, 255)">&quot;bob&quot;</span>));</p><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
// this insert doesn&#39;t evaluate the rule and hence the </p><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">// condition <span style="color:rgb(183, 0, 0)">$u:User(trades &gt;= 3) is not checked</span></p>
<p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="color:rgb(183, 0, 0)"><br></span></p><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"></p><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
session.fireAllRules();</p><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><br></p><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><br></p><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
Thanks &amp; Regards,</p><p style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">Neelesh</p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;color:#b70000">
<span style="color:#000000"><br></span></p><p></p></td></tr></tbody></table><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br> - CTO @ <a href="http://www.plugtree.com">http://www.plugtree.com</a>  <br> - MyJourney @ <a href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
 - Co-Founder @ <a href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br> <br> - Salatino &quot;Salaboy&quot; Mauricio -<br>