Closed willome closed 1 year ago
@willome As I explained in this article, using the id
in the hashCode
method is not going to render consistent results when changing the entity from one state to another.
If this is the AbstractPersistable
implementation, then it's wrong.
The AbstractPersistable
should define the equals
and hashCode
methods like this:
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AbstractPersistable))
return false;
AbstractPersistable other = (AbstractPersistable) o;
return id != null &&
id.equals(other.getId());
}
@Override
public int hashCode() {
return getClass().hashCode();
}
Oh I misread the hashCode problem. Thanks.
My entity is extending spring AbstractPersistable but I have a MAJOR - EqualsHashCodeEvent warning.
Maybe AbstractPersistable is not fully compliant and we should make some changes in the spring data code. I even have tried to extends this class with no sucess:
any ideas ?
Guillaume