Thanks for your kindly reply. For the "mitigated restriction", 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"><<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>></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 <<a href="mailto:xanadu860122@gmail.com">xanadu860122@gmail.com</a>> wrote:<br>
> It is just a test case used to bring up the issue. The real rule condition<br>
> in my business logic is more complex, like<br>
> Order( id == '...', $msg.date > '...', num == $msg.num ). Of course I can<br>
> change to use Message as Pattern to work aournd, but it is too tricky,<br>
> right? And no matter the usage is weird or not, it is legal, right?<br>
><br>
<br>
</div>I can't really say what was legal in 4.0.7, but<br>
$msg: Message()<br>
Order( $msg.date > '...' )<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 == '...') # 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 > "...")<br>
</div>narrows this effort down. Putting a constraint where it belongs is not<br>
a "workaround", it's best practice :)<br>
<span class="HOEnZb"><font color="#888888"><br>
-W<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
> I am using Drools 4.0.7. If later release fixes this bug, I may try to<br>
> upgrade. I don't want to change LHS. It will bring much effort in my<br>
> project.<br>
><br>
><br>
> On 30 March 2012 14:09, FrankVhh <<a href="mailto:frank.vanhoenshoven@agserv.eu">frank.vanhoenshoven@agserv.eu</a>> wrote:<br>
><br>
>> Let me rephrase my question:<br>
>><br>
>> As date is an attribute of message, why don't you use:<br>
>><br>
>> $msg : Message( date > "...")<br>
>><br>
>> Constraining an attribute of Message in the Order pattern seems a weird<br>
>> thing to do.<br>
>><br>
>><br>
>><br>
>> Zeke-3 wrote<br>
>> ><br>
>> > It seems not work.<br>
>> > When I try<br>
>> > *$msg : Message($date : date)<br>
>> > Order ( $date > "Mar-01-2012" )*<br>
>> > I meet error "Unable to create Field Extractor for '$date' of<br>
>> > '[ClassObjectType class=org.drools.examples.HelloWorldExample$Second]'<br>
>> > in<br>
>> > rule 'default' : [Rule name=default, agendaGroup=MAIN, salience=0,<br>
>> > no-loop=false]"<br>
>> ><br>
>> > When I try<br>
>> > *$msg : Message($date : date)<br>
>> > eval ( $date > "Mar-01-2012" )*<br>
>> > If the dialect is "java", I meet error "Rule Compilation error : [Rule<br>
>> > name=default, agendaGroup=MAIN, salience=0, no-loop=false]<br>
>> > org/drools/examples/test/Rule_default_0.java (8:354) : The operator<br>
>> > ><br>
>> > is undefined for the argument type(s) Date, String"<br>
>> > If the dialect is "mvel", I meet the same ClassCastException.<br>
>> ><br>
>> > On 29 March 2012 22:28, FrankVhh &lt;frank.vanhoenshoven@&gt; wrote:<br>
>> ><br>
>> >> This may sound a bit rude, but... why would you want to do such a<br>
>> >> thing?<br>
>> >><br>
>> >> If there is a constraint on the message, then why not put that<br>
>> constraint<br>
>> >> in<br>
>> >> the message structure?<br>
>> >><br>
>> >> Btw, I think it would work by using eval($date < "...") but see no use<br>
>> >> for<br>
>> >> it either.<br>
>> >><br>
>> >><br>
>> >> Joe Zendle wrote<br>
>> >> ><br>
>> >> > did you try:<br>
>> >> ><br>
>> >> > *$msg : Message($date : date)<br>
>> >> > Order ( $date > "Mar-01-2012" )*<br>
>> >> ><br>
>> >> ><br>
>> >> ><br>
>> >> > 2012/3/29 Zeke &lt;xanadu860122@&gt;<br>
>> >> ><br>
>> >> >> Hi, guys:<br>
>> >> >> I meet a strange issue and need your help again... I am using<br>
>> Drools<br>
>> >> >> 4.0.7.<br>
>> >> >> When my rule condition is as *Message( date > "Mar-01-2012" )*,<br>
>> >> >> everything is OK. But if I change it to be as below:<br>
>> >> >> *$msg : Message()<br>
>> >> >> Order ( $msg.date > "Mar-01-2012" )*<br>
>> >> >> I will meet "java.lang.String cannot be cast to java.util.Date"<br>
>> >> >> ClassCastException. "Order" is another fact. I attach the exception<br>
>> >> call<br>
>> >> >> stack. Please check it. It looks like a bug to me. Do we fix it in<br>
>> >> later<br>
>> >> >> release? If so, can you tell me which release contains the fix?<br>
>> >> Thanks!<br>
>> >> >><br>
>> >> >> _______________________________________________<br>
>> >> >> rules-users mailing list<br>
>> >> >> rules-users@.jboss<br>
>> >> >> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>> >> >><br>
>> >> >><br>
>> >> ><br>
>> >> > _______________________________________________<br>
>> >> > rules-users mailing list<br>
>> >> > rules-users@.jboss<br>
>> >> > <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>> >> ><br>
>> >><br>
>> >><br>
>> >> --<br>
>> >> View this message in context:<br>
>> >><br>
>> <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>
>> >> Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
>> >> _______________________________________________<br>
>> >> rules-users mailing list<br>
>> >> rules-users@.jboss<br>
>> >> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>> >><br>
>> ><br>
>> > _______________________________________________<br>
>> > rules-users mailing list<br>
>> > rules-users@.jboss<br>
>> > <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>> ><br>
>><br>
>><br>
>> --<br>
>> View this message in context:<br>
>> <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>
>> Sent from the Drools: User forum mailing list archive at Nabble.com.<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>
><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>