Hi,<div>What Wolfgang is trying to say about &quot;inform&quot; the Drools engine about the update is that you need to use a modify statement in your RHS. Your rule should look like this:</div><div><br><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><font size="2" color="#a00000" face="Courier New"><b>rule</b></font><font size="2" face="Courier New"> </font><font size="2" color="#008000" face="Courier New">&quot;for E band&quot;</font> <br>

<font size="2" face="Courier New">        </font><span class="Apple-style-span" style="border-collapse: separate; font-family: arial; font-size: small; ">lock-on-active true</span><br><font size="2" face="Courier New">        </font><font size="2" color="#a00000" face="Courier New"><b>when</b></font> <br>

<font size="2" face="Courier New">                r : Rating( rate == 1)</font> <br><font size="2" face="Courier New">        </font><font size="2" color="#a00000" face="Courier New"><b>then</b></font> </span></div><div>
<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">                                <span class="Apple-style-span" style="font-family: &#39;Courier New&#39;; font-size: small; ">modify(r){</span><br>

<font size="2" face="Courier New">                   setBand(</font><font size="2" color="#008000" face="Courier New">&quot;EBand&quot;</font><font size="2" face="Courier New">);</font></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><font size="2" face="Courier New"></font>                                </span><span class="Apple-style-span" style="font-family: &#39;Courier New&#39;; border-collapse: collapse; ">}</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "> </span></div>

<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><font size="2" face="Courier New">                System.out.println( </font><font size="2" color="#008000" face="Courier New">&quot;in E band&quot;</font><font size="2" face="Courier New"> ); </font><font size="2" face="Courier New">                </font><br>

<font size="2" color="#a00000" face="Courier New"><b>end</b></font> </span></div><div><br></div><div>This is the way to inform Drools that your Fact is modified. But be careful, because when you modify a Fact, all the rules are evaluated again because the modification could activate another Rule. This will end in an infinite loop (just like Wolfgang mentioned), the &quot;for E band&quot; rule will be executed for ever. That&#39;s why you need to add the no-loop attribute (if the only rule that modifies a Rating is &quot;for E band&quot;) or lock-on-active (if more than one rule could modify a Rating).  </div>

<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br><div class="gmail_quote">On Mon, Mar 29, 2010 at 7:20 AM, Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">You have to inform the Drools engine about the update done with<br>
r.setBand(&quot;...&quot;), or else the query condition is still seeing the fact<br>
state at insert time.<br>
<br>
You may have to add the no-loop option to your rules.<br>
<br>
(Also, comments and actions disagree, e.g. &quot;D Band&quot; vs. &quot;EBand&quot;)<br>
<font color="#888888"><br>
-W<br>
</font><div><div></div><div class="h5"><br>
On 3/29/10, Nilima R &lt;<a href="mailto:nilima.r@tcs.com">nilima.r@tcs.com</a>&gt; wrote:<br>
&gt; Dear All,<br>
&gt;<br>
&gt; I have created simple rule file and created model in that rule file only<br>
&gt;<br>
&gt; package com.sample<br>
&gt;<br>
&gt; import java.lang.String;<br>
&gt;<br>
&gt; declare Rating<br>
&gt; rate : int<br>
&gt; band : String<br>
&gt; name : String<br>
&gt; end<br>
&gt;<br>
&gt; query &quot;employee with band E&quot;<br>
&gt; ratg : Rating(band == &quot;EBand&quot;)<br>
&gt; end<br>
&gt;<br>
&gt; rule &quot;for E band&quot;<br>
&gt;<br>
&gt;         when<br>
&gt;                 r : Rating( rate == 1)<br>
&gt;         then<br>
&gt;                 r.setBand(&quot;EBand&quot;);<br>
&gt;                 System.out.println( &quot;in E band&quot; );<br>
&gt;<br>
&gt; end<br>
&gt;<br>
&gt; rule &quot;for D band&quot;<br>
&gt;<br>
&gt;         when<br>
&gt;                 r : Rating( rate == 2)<br>
&gt;         then<br>
&gt;                 r.setBand(&quot;EBand&quot;);<br>
&gt;                 System.out.println( &quot;in E band&quot; );<br>
&gt;<br>
&gt; end<br>
&gt;<br>
&gt; rule &quot;for C band&quot;<br>
&gt;<br>
&gt;         when<br>
&gt;                 r : Rating( rate == 3)<br>
&gt;         then<br>
&gt;                 r.setBand(&quot;EBand&quot;);<br>
&gt;                 System.out.println( &quot;in E band&quot; );<br>
&gt;<br>
&gt; end<br>
&gt;<br>
&gt; rule &quot;for B band&quot;<br>
&gt;<br>
&gt;         when<br>
&gt;                 r : Rating( rate == 4)<br>
&gt;         then<br>
&gt;                 r.setBand(&quot;EBand&quot;);<br>
&gt;                 System.out.println( &quot;in E band&quot; );<br>
&gt;<br>
&gt; end<br>
&gt;<br>
&gt;<br>
&gt; At the end I want to know how many employees have got E band and so have<br>
&gt; written query for it in the rule file .and obtained the query results as<br>
&gt; below<br>
&gt;<br>
&gt;<br>
&gt; FactType bandType = kbase.getFactType( &quot;com.source&quot;, &quot;Rating&quot; );<br>
&gt;                         QueryResults results = ksession.getQueryResults(<br>
&gt; &quot;employee with band E&quot;);<br>
&gt;                         System.out.println( &quot;we have &quot; + results.size() +<br>
&gt; &quot;employee with band E&quot; );<br>
&gt;                         System.out.println( &quot;employee with band E:&quot; );<br>
&gt;<br>
&gt;                         for (Iterator i = results.iterator();<br>
&gt; i.hasNext();) {<br>
&gt;                             QueryResultsRow row =<br>
&gt; (QueryResultsRow)i.next();<br>
&gt;                             Object ratg = row.get(&quot;rating&quot;);<br>
&gt;                             String name = (String) bandType.get( ratg,<br>
&gt; &quot;name&quot; );<br>
&gt;                             System.out.println(name);<br>
&gt;                          }<br>
&gt;<br>
&gt;<br>
&gt; But am getting the result of query as 0 records.<br>
&gt;<br>
&gt;<br>
&gt; i am inserting objects one by one ( this for testing just purpose ) to<br>
&gt; learn how query works.<br>
&gt;<br>
&gt;<br>
&gt; Can someone plz point out what is wrong.Its Urgent ................<br>
&gt;<br>
&gt;<br>
&gt; Thanks in advance.<br>
&gt; Nilu<br>
&gt; =====-----=====-----=====<br>
&gt; Notice: The information contained in this e-mail<br>
&gt; message and/or attachments to it may contain<br>
&gt; confidential or privileged information. If you are<br>
&gt; not the intended recipient, any dissemination, use,<br>
&gt; review, distribution, printing or copying of the<br>
&gt; information contained in this e-mail message<br>
&gt; and/or attachments to it are strictly prohibited. If<br>
&gt; you have received this communication in error,<br>
&gt; please notify us by reply e-mail or telephone and<br>
&gt; immediately and permanently delete the message<br>
&gt; and any attachments. Thank you<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div><div><div></div><div class="h5">_______________________________________________<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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>Esteban Aliverti<br>
</div>