In short, my question is...
Should UserType.equals(Object x, Object y) return true if both x and y are null?
More thoughts...
In Hibernate version 2.1.6 the javadoc for UserType.equals(Object, Object) doesn't address the contract if both arguments are null.
Code:
/**
* Compare two instances of the class mapped by this type for persistence "equality".
* Equality of the persistent state.
*
* @param x
* @param y
* @return boolean
*/
What does "persistence equality" mean? If it means consistent with sql then the posts I've seen on this form that recommend an implementation like this
Code:
public boolean equals(Object x, Object y) throws HibernateException {
if (x == y) {
return true;
}
if (x == null || y == null) {
return false;
}
return x.equals(y);
}
are not correct (select * from foo where null = null; never returns a row).
But I doubt that is what is meant. Can someone clarify this phrase, please?
Finally, assuming that two nulls should evaluate to true, may I suggest the following as more readable to those familiar with the Object.equals(Object) contract...
Code:
public boolean equals(Object x, Object y) throws HibernateException {
if (x == null) {
return y == null;
}
return x.equals(y);
}