[hibernate-dev] Entity implementation of equals()
Gail Badner
gbadner at redhat.com
Tue Aug 27 19:48:12 EDT 2019
Hi,
I'm looking into the impact of HHH-13590.
In the test for HHH-13590, I see that the mapped superclass entity defines
equals() as:
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
...
}
Due to the bug:
* this is a Project instance;
* o is a HibernateProxy with target == this.
Because the getClass() != o.getClass(), false is returned, and that
ultimately causes the test to fail.
The fix for HHH-13590 results in comparing a Project instance with itself
(not the proxy).
I see that the documentation has a similar implementation of equals() in
"Example 111. Natural Id equals/hashCode" of [1].
In general, is it OK for equals() to require both instances to be of the
same class?
Thanks,
Gail
[1]
https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#mapping-model-pojo-equalshashcode
More information about the hibernate-dev
mailing list