<br>   Just a comment:<br><br>&quot;There is no operator overloading in java, so the &quot;&lt;&quot; operator must act on a numerical primitive. (int, double, etc.) &quot;<br><br>    This is not true. Comparison operators will work on any &quot;comparable&quot; type. So if Quantity implements Comparable interface, it must work. Otherwise it is a bug.<br>
<br>    Although, remember that Drools always makes type coercion from the right to the left value, so, for that to actually work:<br><br>Person( height &lt; $2m )<br><br>    &quot;height&quot; must be comparable to $2m.<br>
<br>     []s<br>     Edson<br><br><br><div class="gmail_quote">2009/2/26 Greg Barton <span dir="ltr">&lt;<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The problem is the &quot;Person( height &lt; $2m )&quot; part.  There is no operator overloading in java, so the &quot;&lt;&quot; operator must act on a numerical primitive. (int, double, etc.)  $2m is a Quantity.  As for why this doesn&#39;t error out, I&#39;m not sure, but it certainly won&#39;t execute. (Unless mvel has some capabilities I&#39;m not aware of.)<br>

<br>
Try<br>
<br>
Person( height &lt; $2m.height )<br>
<br>
...as long as Person.height and Quantity.height are both numerical types.<br>
<br>
If you want to specifically call compareTo() you should use an eval block:<br>
<div class="Ih2E3d"><br>
WHEN<br>
  $meter:UoM( ) from UoMs.get(&quot;length&quot;,&quot;m&quot;)<br>
  $2m:Quantity() from Quantities.get(2,$meter)<br>
</div>  $p: Person()<br>
  eval($p.getHeight().compareTo($2m))<br>
<br>
However, even if this works, I hope you&#39;re not going to be putting too much data through rules like this.  The way it&#39;s currently constructed it completely circumvents all of drools&#39; indexing ability. :)  The power of rules comes from tracking the changes in a set of objects, and firing rules based on only the changes observed.  (That set is the working memory.) The &quot;from&quot; keyword allows you to have rules that draw objects from outside working memory, but you pay for that convenience: the cost is not being able to track changes.  As a result, objects gathered using &quot;from&quot; must be reconsidered even if they haven&#39;t changed (i.e. every time the condition is encountered) because drools has no way of knowing if they&#39;ve changed or not.<br>

<br>
So, after this long winded spiel, here&#39;s my suggestion: get the rule(s) to work using &quot;from&quot; but also try inserting the Quantity object in working memory.  If you&#39;re processing enough data with the rules you will notice a difference.<br>

<div class="Ih2E3d"><br>
--- On Thu, 2/26/09, David Boaz &lt;<a href="mailto:davidb@dbmotion.com">davidb@dbmotion.com</a>&gt; wrote:<br>
<br>
&gt; From: David Boaz &lt;<a href="mailto:davidb@dbmotion.com">davidb@dbmotion.com</a>&gt;<br>
&gt; Subject: Re: [rules-users] Creating objects in WHEN clause<br>
&gt; To: <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
</div>&gt; Date: Thursday, February 26, 2009, 9:13 AM<br>
<div class="Ih2E3d">&gt; Thanks for your all help.<br>
&gt; with your help, my rule looks now as:<br>
&gt; WHEN $meter:UoM( ) from<br>
&gt; UoMs.get(&quot;length&quot;,&quot;m&quot;)<br>
&gt;        $2m:Quantity() from Quantities.get(2,$meter)<br>
&gt;       Person( height &lt; $2m )<br>
&gt;<br>
&gt; My Quantity class implements Comparable interface. When<br>
&gt; running the rule on<br>
&gt; a good dataset (where I expect the rule to fire), the rule<br>
&gt; fails with no<br>
&gt; error. in addition, the compareTo(Object o) method is not<br>
&gt; called (the<br>
&gt; debugger doesn&#39;t stop in this method).<br>
&gt;<br>
&gt; Can you please help?<br>
&gt; Thanks, David<br>
<br>
<br>
<br>
</div><div><div></div><div class="Wj3C7c">_______________________________________________<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>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>