Hi all,
I have encountered a situation I don't quite understand, I would be happy to
have some explanations about it. This is my first post here and I'm quite
new to all this so don't be afraid to go back to basics if I'm missing
something:
I have 3 classes :
public class Child
{
private Date time;
+get
+set
+constructor
}
public class Father
{
private Child child;
private int value;
+get
+set
+constructor
public void setTime(Date d)
{
child.setTime(d);
}
}
public class GdFather
{
private Father father;
+get
+set
+constructor
}
then 2 rules :
rule "1"
when
$father : Father(value==1)
then
$father.setTime(new Date(2));
$father.setValue(0);
update($father);
end
rule "2"
when
$father : Father()
$GdFather : GdFather(father==$father)
then
System.out.println($father);
end
////////////////////////////////////////
I didn't change the identity assert behavior, I insert a father and the
corresponding GdFather in the workingMemory, and all seems to work OK.
The issue occurs when I override the hashCode function in the Father class :
if I use this definition :
@Override
public int hashCode()
{
return child.getTime().hashCode();
}
then rule 2 is not fired after modification of the father, and is not either
if I change the function to return child.hashCode() with a Child hashCode
returning time.hashCode().
This also happens with a properly overriden equals function, and both Drools
5.1.1 and 5.2.0.CR1.
What I don't understand is why is it using the overriden hashCode function
with an identity assert behavior? What is it used for? And it looks like it
is using the overriden hashCode, but not equals, is that correct, and if so,
why?
How can I get the second rule to fire and have a custom hashCode() ?
Thank you in advance for your answers,
M.H.
--
View this message in context:
http://drools.46999.n3.nabble.com/Drools-use-of-hashCode-tp3090424p309042...
Sent from the Drools: User forum mailing list archive at
Nabble.com.