<br>&nbsp;&nbsp; Nope. You must use the update method. You can get the previous fact handle using the get method in working memory if you still have the original non-modified object, or if behavior is equals based, using an equals object.<br>
<br>&nbsp;&nbsp; []<br>&nbsp;&nbsp; Edson<br><br><div class="gmail_quote">2008/5/30 Fenderbosch, Eric &lt;<a href="mailto:Eric.Fenderbosch@fedex.com">Eric.Fenderbosch@fedex.com</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Is it required to use WorkingMemory.update to update an existing fact?<br>
I thought if assert behavior was set to equality and you implemented the<br>
equals method properly, then you could simply use WorkingMemory.insert<br>
to overwrite a fact in working memory with a new version. &nbsp;If this isn&#39;t<br>
the case, then are there other settings that will give this behavior?<br>
<br>
I&#39;m using <a href="http://4.0.7." target="_blank">4.0.7.</a><br>
<br>
Thanks for any help.<br>
<br>
Eric<br>
<br>
Here&#39;s my RuleBaseConfiguration:<br>
AlphaNodeHashingThreshold : 3<br>
CompositeKeyDepth : 3<br>
ExecutorServiceorg.drools.concurrent.DefaultExecutorService<br>
RuleBaseUpdateHandler :<br>
org.drools.base.FireAllRulesRuleBaseUpdateListener<br>
AgendaGroupFactory :<br>
org.drools.common.PriorityQueueAgendaGroupFactory@17653ae<br>
AssertBehaviour : equality<br>
ConflictResolver : org.drools.conflict.DepthConflictResolver@16fe0f4<br>
ConsequenceExceptionHandler :<br>
org.drools.base.DefaultConsequenceExceptionHandler@19d0a1<br>
LogicalOverride : discard<br>
SequentialAgenda : sequential<br>
AlphaMemory : false<br>
IndexLeftBetaMemory : true<br>
IndexRightBetaMemory : true<br>
MaintainTms : true<br>
RemoveIdenities : true<br>
Sequential : false<br>
ShadowProxy : true<br>
ShareAlphaNodes : true<br>
ShareBetaNodes : true<br>
UseStaticObjensis : false<br>
<br>
<br>
My TestFact class:<br>
<br>
public class TestFact {<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;private String id;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;private String value;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public String getId() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return id;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public void setId(String id) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://this.id" target="_blank">this.id</a> = id;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public String getValue() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return value;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public void setValue(String value) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.value = value;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;@Override<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public int hashCode() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return id.hashCode();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;@Override<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public boolean equals(Object obj) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (this == obj) return true;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!(obj instanceof TestFact)) return false;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TestFact other = (TestFact) obj;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// not null safe, i know<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return this.id.equals(<a href="http://other.id" target="_blank">other.id</a>);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
}<br>
<br>
And the JUnit Test Case that fails:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public void testFactUpdate() throws Exception {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TestFact testFact = new TestFact();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;testFact.setId(&quot;1234&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;testFact.setValue(&quot;old&quot;);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FactHandle testFactHandle =<br>
workingMemory.insert(testFact);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TestFact updatedFact = new TestFact();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;updatedFact.setId(&quot;1234&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;updatedFact.setValue(&quot;new&quot;);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FactHandle updatedFactHandle =<br>
workingMemory.insert(updatedFact);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// using workingMemory.update here works<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// passes<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;assertTrue(testFactHandle == updatedFactHandle);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TestFact retrievedTestFact = (TestFact)<br>
workingMemory.getObject(testFactHandle);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// fails<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;assertEquals(&quot;new&quot;, retrievedTestFact.getValue());<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<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>
</blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>