IMO, you have not informed the engine\RETE network that details have changed
in your first example.
This would probably be a better example:-
rule "30 is the new 20"
when
person : Person( $d : details.age == 30 )
then
person.getDetails().setAge(20);
System.out.println( "Now 20 : " + person );
update( person );
update( $d );
end
The From works because it gets external data rather than using that already
in the engine\RETE network.
IMO, I think the rules are working correctly; it's just a misunderstanding
of how the engine\RETE network function.
I hope this helps.
Thanks,
Mike
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Aaron Dixon
Sent: 14 March 2008 20:51
To: Rules Users List
Subject: [rules-users] Can only reason over sub-objects if you use the
FromConditional Element
It appears that you MUST use the From Condition Element to reason over
sub-objects.
I have a Person class. Person::getDetails() returns a Details
instance, which has the name and age of the person. (This is a
contrived example to demonstrate the issue.)
My rules are:
rule "30 is the new 20"
when
person : Person( details.age == 30 )
then
person.getDetails().setAge(20);
System.out.println( "Now 20 : " + person );
update( person );
end
rule "Older than 20 - Good"
salience -100
when
person : Person( )
Details( age > 20 ) from person.details
then
System.out.println( "Older than 20 (good) : " + person );
end
rule "Older than 20 - Bad"
salience -100
when
person : Person( details.age > 20 )
then
System.out.println( "Older than 20 (bad) : " + person );
end
I assert Abe, Bob, Cat, Don, and Eve with ages of 10, 20, 30, 40, and
50, respectively. The output is as follows.
Now 20 : Person(Details(Cat,20))
Older than 20 (good) : Person(Details(Eve,50))
Older than 20 (bad) : Person(Details(Eve,50))
Older than 20 (good) : Person(Details(Don,40))
Older than 20 (bad) : Person(Details(Don,40))
Older than 20 (bad) : Person(Details(Cat,20))
You can see that the "Bad" rule is more concise but it does not use
the From Conditional Element and therefore it doesn't work properly
(Cat is determined to be older than 20 when she is not.)
Why does Drools allow the "Bad" rule to be written and compiled when
it does not behave properly?
Thanks,
Aaron
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users