Hello,
I am a bit confused about how insertLogical() supposed to work in drools 5.
when i have a rule such as:
rule "fact = 1"
when
$f : UserFact(fact1 == 1);
then
insertLogical(new CreatedFact($f.getFact2()));
end
now i change $f in such a way, that the rule will fire again.
via
// build first version
UserFact f = new UserFact();
f.setFact1(1);
f.setFact2(1);
memory.insert(f);
memory.fireAllRules(); // <- Rule fires once
// now i change the memory and fire the rules again
memory.modifyRetract(f) ;
f.setFact2(100); // <- changing $f, but leaving fact1 as it is.
memory.modifyInsert(f);
memory.fireAllRules(); // <- Rule fires again
now the rule should fire again, which it does.
but i end up with two CreatedFact instances in the workingMemory..
one with the old OtherFact value 1, and one with the new value, 100
but i want only the second instance. the one created first is not valid any
more.
i could write an extra rule for retracting the first CreatedFact-fact, but
then i would have
a very tight coupling of the two rules.
is there a better way?
it seems odd to me, that a consequence of a rule stays in memory, when there
is
a more current version of the rule evocation with the _same_ facts in the
precondition
and a different consequence.
thanks in advance, tim