Assert behaviour merely defines the engine&#39;s reaction w.r.t. to the insertion of another fact that might be considered being &quot;the same as&quot; one that&#39;s already in the WM. This is due to the simple truth that facts represent true propositions (and that you aren&#39;t the <a href="http://www.theotherpages.org/poems/carrol03.html">Bellman</a>.) <br>
<br>For hashCode() and equals() you must follow the usual Java rules.<br><br>-W<br><br><br>On 21 June 2011 14:29, M. H. &lt;<a href="mailto:hugues_81@hotmail.com">hugues_81@hotmail.com</a>&gt; wrote:<br>&gt; Hi all,<br>&gt;<br>
&gt; I have encountered a situation I don&#39;t quite understand, I would be happy to<br>&gt; have some explanations about it. This is my first post here and I&#39;m quite<br>&gt; new to all this so don&#39;t be afraid to go back to basics if I&#39;m missing<br>
&gt; something:<br>&gt;<br>&gt; I have 3 classes :<br>&gt;<br>&gt; public class Child<br>&gt; {<br>&gt;        private Date time;<br>&gt; +get<br>&gt; +set<br>&gt; +constructor<br>&gt; }<br>&gt;<br>&gt; public class Father<br>
&gt; {<br>&gt;        private Child child;<br>&gt;        private int value;<br>&gt; +get<br>&gt; +set<br>&gt; +constructor<br>&gt;        public void setTime(Date d)<br>&gt;        {<br>&gt;                child.setTime(d);<br>
&gt;        }<br>&gt; }<br>&gt;<br>&gt; public class GdFather<br>&gt; {<br>&gt;        private Father father;<br>&gt; +get<br>&gt; +set<br>&gt; +constructor<br>&gt; }<br>&gt;<br>&gt; then 2 rules :<br>&gt;<br>&gt; rule &quot;1&quot;<br>
&gt;        when<br>&gt;                $father : Father(value==1)<br>&gt;        then<br>&gt;                $father.setTime(new Date(2));<br>&gt;                $father.setValue(0);<br>&gt;                update($father);<br>
&gt; end<br>&gt;<br>&gt; rule &quot;2&quot;<br>&gt;        when<br>&gt;                $father : Father()<br>&gt;                $GdFather : GdFather(father==$father)<br>&gt;        then<br>&gt;                System.out.println($father);<br>
&gt; end<br>&gt;<br>&gt; ////////////////////////////////////////<br>&gt;<br>&gt; I didn&#39;t change the identity assert behavior, I insert a father and the<br>&gt; corresponding GdFather in the workingMemory, and all seems to work OK.<br>
&gt; The issue occurs when I override the hashCode function in the Father class :<br>&gt; if I use this definition :<br>&gt; @Override<br>&gt;        public int hashCode()<br>&gt;        {<br>&gt;                return child.getTime().hashCode();<br>
&gt;        }<br>&gt; then rule 2 is not fired after modification of the father, and is not either<br>&gt; if I change the function to return child.hashCode() with a Child hashCode<br>&gt; returning time.hashCode().<br>&gt; This also happens with a properly overriden equals function, and both Drools<br>
&gt; 5.1.1 and 5.2.0.CR1.<br>&gt; What I don&#39;t understand is why is it using the overriden hashCode function<br>&gt; with an identity assert behavior? What is it used for? And it looks like it<br>&gt; is using the overriden hashCode, but not equals, is that correct, and if so,<br>
&gt; why?<br>&gt; How can I get the second rule to fire and have a custom hashCode() ?<br>&gt;<br>&gt; Thank you in advance for your answers,<br>&gt;<br>&gt;<br>&gt; M.H.<br>&gt;<br>&gt; --<br>&gt; View this message in context: <a href="http://drools.46999.n3.nabble.com/Drools-use-of-hashCode-tp3090419p3090419.html">http://drools.46999.n3.nabble.com/Drools-use-of-hashCode-tp3090419p3090419.html</a><br>
&gt; Sent from the Drools: User forum mailing list archive at Nabble.com.<br>&gt; _______________________________________________<br>&gt; rules-users mailing list<br>&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>&gt;<br><br>