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