I have seen the following implementation in a repository and I am confused:
@Entity
@Getter
@Setter
@ToString(callSuper = true)
@NoArgsConstructor
public class Employee extends BaseEntity {
// properties
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public boolean equals(Object other) {
return super.equals(other);
}
}
My questions are:
Is it logical to implement these methods as they are already implemented in the base class? Is it unnecessary to implement hashCode()
, equals()
methods here and adding @ToString(callSuper = true)
to the beginning of the entity class?
For adding these methods in the entity, is it better to use annotation instead of adding 3-4 lines code for each method?
I think there is a misuse regarding to these methods. Because 2 of them are implemented and one of them (toString
) is added via annotation. I think all of them should be used in the same manner (all of them via annotation or all of them via implementation). Am I wrong?
hashCode()
and equals()
.