Your rule doesn't make sense to me. It accumulates three Sets for cardinality tests from the same domain ($loan.garantees) by filtering these objects by the constraints:<br> Set-1: typegarantee.code == "H"<br>
Set-2: typegarantee.code == "H" || typegarantee.code == "O"<br> Set-3: typegarantee.code == "H"<br>Clearly Set-1 and Set-3 will have the same cardinality - so why compute and test it twice?<br>
Obviously, the second set will only have cardinality one if there are no "garantee" facts with typegarantee.code == "O", and so this is a weird way of asserting that.<br><br>Cardinality tests are better written using the accumulate function "count".<br>
<br>There is no point in writing<br> $loan : loan() from $loanEvaluated.loan<br>if $loanEvaluated.loan is not a Collection. Simply use:<br> $loanEvaluated : loanEvaluated(..., $loan : loan )<br><br>The frequent use of "from $loan.garantees" insinuates that the "garantee" objects contained in the loan.garantee Collection should be inserted as facts, preferably with a link field to the "loan" fact they belong to. This would make evaluation much more efficient, and there wouldn't be much of repeated evaluation going on after some other rule updates loanEvaluated.<br>
<br>However, a general solution of the multiple update might still be advisable. This can be done by<br><ul><li>saving all computed update values (such as "initial value") in an object S separate from loanEvaluated (possibly but not necessarily of the same type),</li>
<li><i>not </i>updating this temporary safekeeping object S,</li><li>using a low salience rule to transfer whatever is in S to the pertaining loanEvaluated. (Alternatively, you might employ agenda groups for the simple flow between main and computation.)<br>
</li></ul>-W<br><br>PS: You might adhere to the Java naming conventions using upper case initials for type names.<br>PPS: The correct spelling is "g<b>u</b>arantee".<br><br><br><div class="gmail_quote">On 25 May 2011 01:55, dbfree75 <span dir="ltr"><<a href="mailto:wbismuth@yahoo.fr">wbismuth@yahoo.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I'm still using such solution .<br>
Here an example of rule where I nees to set the<br>
originalPropertyValuationLoan :<br>
<br>
rule "OriginalPropertyValuationLoan - NbSecuredGaranteeUnderLoan >= 1 -<br>
garantee H - postCode equivalent - initialValue equivalent"<br>
no-loop<br>
salience 970<br>
dialect "mvel"<br>
when<br>
<br>
$controlFact : ControlFact(phase == "INITIAL")<br>
$loanEvaluated : loanEvaluated(nbSecuredGaranteeUnderLoan >= 1,<br>
originalPropertyValuationLoan == null)<br>
$loan : loan() from $loanEvaluated.loan<br>
$garantee : garantee(typegarantee.code == "H" , initialValue != null) from<br>
$loan.garantees<br>
$postCodes : Set(size == 1)<br>
from accumulate(<br>
garantee(typegarantee.code == "H", $n :<br>
postCodeInGarantee) from $loan.garantees,<br>
collectSet($n)<br>
)<br>
$garantees : Set(size == 1)<br>
from accumulate(<br>
garantee(typegarantee.code == "H" ||<br>
typegarantee.code == "O", $n : typegarantee.code) from $loan.garantees,<br>
collectSet($n)<br>
)<br>
$initialValue : Set(size == 1)<br>
from accumulate(<br>
<br>
garantee(typegarantee.code == "H", $n : initialValue ) from $loan.garantees,<br>
collectSet($n)<br>
)<br>
then<br>
$loanEvaluated.originalPropertyValuationLoan = $garantee.initialValue<br>
update($loanEvaluated)<br>
#System.out.println("OriginalPropertyValuationLoan -<br>
NbSecuredGaranteeUnderLoan > 1 : " +<br>
$loan.loanEvaluated.originalPropertyValuationLoan);<br>
end<br>
<br>
In case this rule isn't fired because any of these conditions isn't set, on<br>
update after any other property has been set this rule will be fired again<br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Update-function-usage-for-java-objects-to-be-retrieved-for-database-update-tp2981879p2982338.html" target="_blank">http://drools.46999.n3.nabble.com/Update-function-usage-for-java-objects-to-be-retrieved-for-database-update-tp2981879p2982338.html</a><br>
</font><div><div></div><div class="h5">Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>