What happens if you insert two Product/Option pairs, one with the price
already set and the other still with price == null?
One thing that could explain the effect you describe it is calling
ksession.fireAllRules( 1 )
to run the engine. If this isn't the cause, we'd need to see all the code,
in a minimum examle to reproduce this.
-W
On 5 April 2011 05:38, groovenarula <gnarula1(a)la-z-boy.com> wrote:
Hello all,
For some reason I have a rule that does not fire after a Modify/Update.
I have 2 facts - Product and Option. The relationship between them is that
a
'Product' can have 0 - N 'Option'(s).
Based on that, I added a 'product' field to the 'Option' object. I'm
creating and inserting my facts
using the following code :
Product prod = new Product ("001","002",
"A");
prod.setPrice(new BigDecimal("300.00"));
Option opt = new Option ("H1","",prod);
ksession.insert(prod);
ksession.insert(opt);
Now in my .DLR, I have the following rule :
rule "Set Options price"
salience 50
when
$prod : Product ( price != null )
$option : Option ( product == $prod )
then
System.out.println( "Getting Options " + $prod );
end
This gives me the correct output in the console :
Getting Options Product [category=001, grade=A, price=300.00, style=002]
The rule fired successfully.
I start running into problems when I try to update the 'price' field using
a
rule, instead of through code.
So for example, if I have the following rule also defined in the same drl
file :
rule "Set price"
salience 500
when
$prod : Product ( category == "001", price == null )
then
$prod.setPrice ( new BigDecimal ( "300.00" ) );
update( $prod );
System.out.println( $prod );
end
And then change my code as follows (remove the setPrice call) :
Product prod = new Product ("001","002",
"A");
Option opt = new Option ("H1","",prod);
ksession.insert(prod);
ksession.insert(opt);
I only get the following output :
Product [category=001, grade=A, price=300.00, style=002]
What am I missing here ? I thought the rule 'Set Price' should update the
product fact with
the new price and the rules would get re-evaluated. After the
re-evaluation,
the LHS of 'Set Options Price' should now be true and it should have fired.
But it does not.
Am I mis-understanding something about activation here ? If I am, can
someone please help explain what the gap is and how to re-write the rules
so
that I can achieve the above objective ?
Any help will be appreciated. I've spend several hours trying different
permutations and combinations and got no where.
Thanks
Gurvinder
--
View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/Rule-does-not-fire-af...
Sent from the Drools - User mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users