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

Wolfgang Laun wolfgang.laun at gmail.com
Fri Apr 13 04:46:00 EDT 2012


5.3.0 and 5.4.0.Beta2: Comparing int and Integer fails unless the
traditional (up to 5.1.1) "return value" construct - parentheses
around the expression - is used:

 lineItemId == ($lineItem.getID())  // OK
 lineItemId == ($id)   // OK with $id bound as LineItem( $id: ID > 0 )

This would work if ID were public:
 lineItemId == ($lineItem.ID)

It's best to stay as close as possible to the Java Beans conventions.

Using an upper case initial in field names wasn't accepted by the
Drools compiler prior to 5.3.0.




On 12/04/2012, Vincent LEGENDRE <vincent.legendre at eurodecision.com> wrote:
> Or may be something more basic : drools does not 'interpret' Integer types
> as int, so == is testing object references ...
> This explanation explain why it compiles but not working, whereas if my
> previous ideas are right, it should raise a compilation error ...
>
> Try using 'int', or use Integer.valueOf(1) (that will return a shared
> instance of Integer).
> But this is still very strange as doing the same test in java works (Integer
> is treated as a int, and == is testing values ...)
>
>
> ----- Mail original -----
> De: "Vincent LEGENDRE" <vincent.legendre at eurodecision.com>
> À: "Rules Users List" <rules-users at lists.jboss.org>
> Envoyé: Jeudi 12 Avril 2012 20:44:41
> Objet: Re: [rules-users] Trying to compare variables of two objects,	not
> working. (compiles, but not desired result)
>
> 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 ...
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>




More information about the rules-users mailing list