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
Describe the bug
Abstract Superclass for all JPA-Entities
@MappedSuperclass
public abstract class AbstractEntity implements Serializable {
@Id
@Column(unique = true, updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE)
protected Long id;
// getters/setters/constructors removed for brevity
@Override
public final boolean equals(Object o) { // final as suggested on https://jqno.nl/equalsverifier/manual/jpa-entities
// according to https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
if (this == o) return true;
if (!(o instanceof AbstractEntity)) return false;
AbstractEntity other = (AbstractEntity) o;
return id != null && Objects.equals(getId(), other.getId());
}
@Override
public final int hashCode() { // final as suggested on https://jqno.nl/equalsverifier/manual/jpa-entities
// according to https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
}
Example JPA-Entity as Subclass
@Entity
public class Person extends AbstractEntity {
private String name;
// getters/setters/constructors removed for brevity
}
To Reproduce
First try with Warning.SURROGATE_KEY because we have one
Message: Significant fields: equals does not use name, or it is stateless.
This is not as expected because I have an @id field and I say "suppress(Warning.SURROGATE_KEY)".
Nevertheless, complains EqualsVerifier that "name" is not used for equality.
Code that triggers the behavior
See above
Error message
See above
Expected behavior
I expected that EqualsVerifier ignores all Entity fields except @id field
Version
3.13
Additional context
The text was updated successfully, but these errors were encountered:
Describe the bug
Abstract Superclass for all JPA-Entities
Example JPA-Entity as Subclass
To Reproduce
First try with Warning.SURROGATE_KEY because we have one
Message: Reflexivity: object does not equal an identical copy of itself:
If this is intentional, consider suppressing Warning.IDENTICAL_COPY
Yes, this is intentional, therefore
Message: Significant fields: equals does not use name, or it is stateless.
This is not as expected because I have an @id field and I say "suppress(Warning.SURROGATE_KEY)".
Nevertheless, complains EqualsVerifier that "name" is not used for equality.
Code that triggers the behavior
See above
Error message
See above
Expected behavior
I expected that EqualsVerifier ignores all Entity fields except @id field
Version
3.13
Additional context
The text was updated successfully, but these errors were encountered: