[rules-users] Trying to compare variables of two objects, not working. (compiles, but not desired result)

Vincent LEGENDRE vincent.legendre at eurodecision.com
Thu Apr 12 14:44:41 EDT 2012


I think (not sure) that the problem comes from the right part of your test : $lineItem.ID 
Try with $lineItem.getID(), or use 'dialect "mvel"' as rule property

You can also bind the id in LineItem and test it in the next pattern :
 
rule "Test"
    when
      	$lineItem : LineItem( $lineID : ID > 0 )
        $trans : TransactionItem( ID > 0, AccountName != null, LineItemID == $lineID)
        $amount : AccountingItem( TransactionID > 0, CalculatedCommission > 0.0 )
    then
        System.out.println( $amount.getCalculatedCommission() + " " + $lineItem.getID() );
end


But this is very strange. To me it should work ...

What is not usual too is your use of "_" before member attributes (let me guess, you did a lot of C++ ?), which is not the java POJO standards. And may be that drools relies on fields names too ...
And inside your tests, instead of "LineItemID" you should use "lineItemID" (with a lower case letter first, like the name your internal attribute should have, following the common java conventions).

But if all of this is a problem, the symptom should be a compilation error .... so it is still strange ...



More information about the rules-users mailing list