Thanks for your kindly reply. For the &quot;mitigated restriction&quot;, do you mean I can use Order( eval( $msg.getDate().compareTo( new Date(...) ) ) ) # in 5.2.0 and 5.3.0? Can you give me any example or tell me any manual I can reference to?<br>
<br>Thank you!<br><br><div class="gmail_quote">On 31 March 2012 13:06, 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">
<div class="im">On 31/03/2012, Zeke &lt;<a href="mailto:xanadu860122@gmail.com">xanadu860122@gmail.com</a>&gt; wrote:<br>
&gt; It is just a test case used to bring up the issue. The real rule condition<br>
&gt; in my business logic is more complex, like<br>
&gt; Order( id == &#39;...&#39;, $msg.date &gt; &#39;...&#39;, num == $msg.num ). Of course I can<br>
&gt; change to use Message as Pattern to work aournd, but it is too tricky,<br>
&gt; right? And no matter the usage is weird or not, it is legal, right?<br>
&gt;<br>
<br>
</div>I can&#39;t really say what was legal in 4.0.7, but<br>
   $msg: Message()<br>
   Order( $msg.date &gt; &#39;...&#39; )<br>
was not legal in 5.1.1. For any constraint, the left hand side would have to<br>
be a reference to a field of the fact where it occurs.<br>
   Order(Id == &#39;...&#39;) # is OK<br>
You can refer to fields of another fact on the RHS:<br>
  Order(num == $msg.num ) # is OK<br>
Any other expression would have to be written in clean Java (or MVEL)<br>
but enclosed in eval()<br>
  Order( eval( $msg.getDate().compareTo( new Date(...) ) == 1 ) ) # or<br>
similar ;-)<br>
<br>
Starting with 5.2.0, this restriction was mitigated and by 5.3.0 and<br>
certainly in 5.4.0 a wide range of (boolean) expressions is<br>
acceptable.<br>
<br>
However, I should emphasize that postponing the use of a constraint<br>
into a later pattern is an antipattern for rule coding. Consider<br>
    $msg: Message()<br>
This matches any fact of type Message, and the Engine must needs keep<br>
track of this. Contrariwise,<br>
<div class="im">   $msg: Message( date &gt; &quot;...&quot;)<br>
</div>narrows this effort down. Putting a constraint where it belongs is not<br>
a &quot;workaround&quot;, it&#39;s best practice :)<br>
<span class="HOEnZb"><font color="#888888"><br>
-W<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
&gt; I am using Drools 4.0.7. If later release fixes this bug, I may try to<br>
&gt; upgrade. I don&#39;t want to change LHS. It will bring much effort in my<br>
&gt; project.<br>
&gt;<br>
&gt;<br>
&gt; On 30 March 2012 14:09, FrankVhh &lt;<a href="mailto:frank.vanhoenshoven@agserv.eu">frank.vanhoenshoven@agserv.eu</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Let me rephrase my question:<br>
&gt;&gt;<br>
&gt;&gt; As date is an attribute of message, why don&#39;t you use:<br>
&gt;&gt;<br>
&gt;&gt;               $msg : Message( date &gt; &quot;...&quot;)<br>
&gt;&gt;<br>
&gt;&gt; Constraining an attribute of Message in the Order pattern seems a weird<br>
&gt;&gt; thing to do.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Zeke-3 wrote<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; It seems not work.<br>
&gt;&gt; &gt; When I try<br>
&gt;&gt; &gt; *$msg : Message($date : date)<br>
&gt;&gt; &gt; Order ( $date &gt; &quot;Mar-01-2012&quot; )*<br>
&gt;&gt; &gt; I meet error &quot;Unable to create Field Extractor for &#39;$date&#39; of<br>
&gt;&gt; &gt; &#39;[ClassObjectType class=org.drools.examples.HelloWorldExample$Second]&#39;<br>
&gt;&gt; &gt; in<br>
&gt;&gt; &gt; rule &#39;default&#39; : [Rule name=default, agendaGroup=MAIN, salience=0,<br>
&gt;&gt; &gt; no-loop=false]&quot;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; When I try<br>
&gt;&gt; &gt; *$msg : Message($date : date)<br>
&gt;&gt; &gt; eval ( $date &gt; &quot;Mar-01-2012&quot; )*<br>
&gt;&gt; &gt; If the dialect is &quot;java&quot;, I meet error &quot;Rule Compilation error : [Rule<br>
&gt;&gt; &gt; name=default, agendaGroup=MAIN, salience=0, no-loop=false]<br>
&gt;&gt; &gt;     org/drools/examples/test/Rule_default_0.java (8:354) : The operator<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; is undefined for the argument type(s) Date, String&quot;<br>
&gt;&gt; &gt; If the dialect is &quot;mvel&quot;, I meet the same ClassCastException.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On 29 March 2012 22:28, FrankVhh &amp;lt;frank.vanhoenshoven@&amp;gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; This may sound a bit rude, but... why would you want to do such a<br>
&gt;&gt; &gt;&gt; thing?<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; If there is a constraint on the message, then why not put that<br>
&gt;&gt; constraint<br>
&gt;&gt; &gt;&gt; in<br>
&gt;&gt; &gt;&gt; the message structure?<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Btw, I think it would work by using eval($date &lt; &quot;...&quot;) but see no use<br>
&gt;&gt; &gt;&gt; for<br>
&gt;&gt; &gt;&gt; it either.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Joe Zendle wrote<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; did you try:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;  *$msg : Message($date : date)<br>
&gt;&gt; &gt;&gt; &gt; Order ( $date &gt; &quot;Mar-01-2012&quot; )*<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; 2012/3/29 Zeke &amp;lt;xanadu860122@&amp;gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; Hi, guys:<br>
&gt;&gt; &gt;&gt; &gt;&gt;   I meet a strange issue and need your help again... I am using<br>
&gt;&gt; Drools<br>
&gt;&gt; &gt;&gt; &gt;&gt; 4.0.7.<br>
&gt;&gt; &gt;&gt; &gt;&gt;   When my rule condition is as *Message( date &gt; &quot;Mar-01-2012&quot; )*,<br>
&gt;&gt; &gt;&gt; &gt;&gt; everything is OK. But if I change it to be as below:<br>
&gt;&gt; &gt;&gt; &gt;&gt;   *$msg : Message()<br>
&gt;&gt; &gt;&gt; &gt;&gt;   Order ( $msg.date &gt; &quot;Mar-01-2012&quot; )*<br>
&gt;&gt; &gt;&gt; &gt;&gt;   I will meet &quot;java.lang.String cannot be cast to java.util.Date&quot;<br>
&gt;&gt; &gt;&gt; &gt;&gt; ClassCastException. &quot;Order&quot; is another fact. I attach the exception<br>
&gt;&gt; &gt;&gt; call<br>
&gt;&gt; &gt;&gt; &gt;&gt; stack. Please check it. It looks like a bug to me. Do we fix it in<br>
&gt;&gt; &gt;&gt; later<br>
&gt;&gt; &gt;&gt; &gt;&gt; release? If so, can you tell me which release contains the fix?<br>
&gt;&gt; &gt;&gt; Thanks!<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; &gt;&gt; rules-users mailing list<br>
&gt;&gt; &gt;&gt; &gt;&gt; rules-users@.jboss<br>
&gt;&gt; &gt;&gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; &gt; rules-users mailing list<br>
&gt;&gt; &gt;&gt; &gt; rules-users@.jboss<br>
&gt;&gt; &gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; --<br>
&gt;&gt; &gt;&gt; View this message in context:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; <a href="http://drools.46999.n3.nabble.com/rules-users-ClassCastException-when-comparing-date-type-with-literal-tp3867229p3867832.html" target="_blank">http://drools.46999.n3.nabble.com/rules-users-ClassCastException-when-comparing-date-type-with-literal-tp3867229p3867832.html</a><br>

&gt;&gt; &gt;&gt; Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; rules-users mailing list<br>
&gt;&gt; &gt;&gt; rules-users@.jboss<br>
&gt;&gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; rules-users mailing list<br>
&gt;&gt; &gt; rules-users@.jboss<br>
&gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; View this message in context:<br>
&gt;&gt; <a href="http://drools.46999.n3.nabble.com/rules-users-ClassCastException-when-comparing-date-type-with-literal-tp3867229p3870029.html" target="_blank">http://drools.46999.n3.nabble.com/rules-users-ClassCastException-when-comparing-date-type-with-literal-tp3867229p3870029.html</a><br>

&gt;&gt; Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;<br>
&gt;<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>
</div></div></blockquote></div><br>