You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the hasCode() methods generated by Jhipster it appears
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
I also got a bug because of this implementation issue in generated equals. Thanks for creating this issue!
I see however that this change was already done in the past in #5604 , but then changed back here 1973fc6#diff-b2f9dbf1a993c204d3446d607494894a72f73dfb38228358c8e97b4d9d13da1c related to #8656 . I'm not sure that the rollback was intentional, as the goal of the fix for the issue 8656 was to allow comparison with subclasses (so getClass() was replaced by instanceof). I don't see any reason that would explain why the getters were removed in the fix of issue 8656.
Overview of the issue
Jhipster generates the equals methods like this:
Motivation for or Use Case
This implementation is problematic with entities wrapped in hibernate proxies:
https://blog.andrewbeacock.com/2008/08/how-to-implement-hibernate-safe-equals.html
In the hasCode() methods generated by Jhipster it appears
but that implementation:
https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
is not respected with getId in the equals methods generated by jhipster
Suggest a Fix
A correct implementation for hibernate proxies would be (with "getId()" instead of "id"):
JHipster Version(s)
Jhipster 8.0.0 - beta 3
The text was updated successfully, but these errors were encountered: