[Error] Generating equals/hashCode implementation

2022. 7. 13. 17:32Back-end/Spring

반응형

빌드를 시도했더니 빌드가 되지 않는다... 얼라리요?

 

java:16: 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
    ^

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SendMessageRequest extends RequestPaging {
    private String type;        // 메시지 유형. S:SMS, L:LMS
    private String callback;   // 발신번호
    private String title;       // 메시지 제목
    private String text;        // 메시지 내용
    private String list;       // 대상
}

SendMessageRequest Dto가 RequestPaging을 상속받고 있다.

@SuperBuilder
@Slf4j
@Data
public class RequestPaging {
    @ApiModelProperty(value = "현재 페이지", position = 100, dataType = "int")
    private int page = 1;
    @ApiModelProperty(value = "페이징 사이즈", position = 101, dataType = "int")
    private int size = 10;

    @ApiModelProperty(value = "시작", position = 102, dataType = "int", hidden = true)
    private int start;
    @ApiModelProperty(value = "끝", position = 103, dataType = "int", hidden = true)
    private int end;
    @ApiModelProperty(value = "결과", position = 104, dataType = "int", hidden = true)
    private int offset;

    public RequestPaging() {
    }

    public int getPage() {
        if (this.page <= 0) {
            this.page = 1;
        }
        return this.page;
    }

    public int getSize() {
        if (this.size <= 0) {
            this.size = 10;
        }
        return this.size;
    }

    public int getStart() {
        if (this.page <= 1) {
            return 0;
        }
        return ((this.page - 1) * this.size) + 1;
    }

    public int getEnd() {
        return this.page * this.size;
    }

    public int getOffset() {
        return (getPage() - 1) * getSize();
    }

    public void setPaging(int pageNumber, int size) {
        if (pageNumber <= 1) {
            this.setStart(0);
        } else {
            this.setStart(((pageNumber - 1) * size) + 1);
        }
        this.setEnd(pageNumber * size);
    }

    public PageRequest getPageRequest() {
        return PageRequest.of(page - 1, size);
    }

    public RequestPaging getPaging() {
        return this;
    }
}

SendMessageRequest Dto와 RequestPaging 두 군데 다 어노테이션 Data를 사용하고있다.

그래서 jpa가 "어느 @Data의 equls를 사용할 거냐? 두군데 다 있는데?" 라고 하는거다...

 

@EqualsAndHashCode(callSuper = false)

이 어노테이션 하나를 추가하여 callSuper를 false하겠다.

즉 자식클래스인 SendMessageRequest의 @Data를 사용하겠다고 해주는 것이다.

@Data
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@NoArgsConstructor
public class SendMessageRequest extends RequestPaging {
    private String type;        // 메시지 유형. S:SMS, L:LMS
    private String callback;   // 발신번호
    private String title;       // 메시지 제목
    private String text;        // 메시지 내용
    private String list;       // 대상
}

 

빌드가 잘 된다.

반응형