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)
@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
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.