Reputation: 658
I have JPA entity that extends other abstract class. I want to use @Data to avoid writing setters and getters but my equals and hashcode methods exists.
I get warning but I think I should not:
server\entity\User.java:20: warning: Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.
@Data
^
In my User class:
@Data
@Entity
public class User extends AbstractAuditingEntity implements Serializable {
....
@Override
public boolean equals(Object o) {
...
}
@Override
public int hashCode() {
...
}
}
When I add additionally @EqualsAndHashCode(callSuper = false) to @Data I get:
server\entity\User.java:21: warning: Not generating equals and hashCode: A method with one of those names already exists. (Either both or none of these methods will be generated).
@EqualsAndHashCode(callSuper = false)
Upvotes: 8
Views: 15980
Reputation: 7394
@Data
is a shortcut for @ToString
, @EqualsAndHashCode
, @Getter
, @Setter
, and @RequiredArgsConstructor
. Since you just want @Getter
and @Setter
, why don't you just use them (this will avoid your exception or warning messages),
@Entity
@Getter
@Setter
public class User extends AbstractAuditingEntity implements Serializable
...
}
Upvotes: 20