I am having problem working on overriding hashCode() method when if reference other objects to get their properties.
Here is the sample:
public int hashCode() {
int result = HashCodeUtil.SEED;
result = HashCodeUtil.hash(result, this.otherOjb1.getName());
result = HashCodeUtil.hash(result, this.otherObj2.getName());
return result;
}
The problem is that when I use EJB and then it breaks. The exception is a "NullPointerException". It seems to me is the otherObj1 is null during the serialization. If I do this and it works fine:
public int hashCode() {
int result = HashCodeUtil.SEED;
if(otherObj1 != null && otherObje2 != null) {
result = HashCodeUtil.hash(result, this.otherOjb1.getName());
result = HashCodeUtil.hash(result, this.otherObj2.getName());
}
else {
result = HashCodeUtil.hash(result, agency);
result = HashCodeUtil.hash(result, broker);
}
return result;
}
Any thoghts?
Thanks,
J
|