Search code examples
droolsbusiness-process-management

Some rule is not fired again when fact is modified


I have fired the rule by setting discount as 5. Why 'rule 1' is not fired again when fact (Product) is modified in 'rule 3'

Output

Rule 1 Rule 2 Rule 3

Rule 2 Rule 3

Rule 2 Rule 3

Code

rule "Rule 1"

when
    eval(true)
then
        System.out.println("Rule 1");
end

rule "Rule 2"

when 
    $c: Product(discount < 8 && discount > 3)
then
    System.out.println("Rule 2");

end


rule "Rule 3" 

when
    $c: Product(discount < 8 && discount > 3)
then
    System.out.println("Rule 3");
    modify($c){ 
        setDiscount($c.getDiscount()+1) 
    }

    System.out.println("--------------");
end 

Solution

  • A rule not containing a fact type in a LHS pattern cannot be affected by any change to any of the facts of the unreferenced type.

    Product is not referenced in "Rule 1".