1:N 관계에서

22.10.16 00:27 작성 조회수 138

0

특정 게시글을 조회하고 싶을 때 작성된 댓글들도 같이 보고 싶은데 InvalidDefinitionException: Direct self-reference leading to cycle 관련하여 에러가 뜹니다.

@JsonIgnore로 해결하기보다 ResponseDto로 만들어서 entity -> ResponseDto로 변환해서 응답하고 싶습니다.

그래서 ResponseDto를 만들어서 entity -> ResponseDto로 변환했는데 저런 에러가 뜹니다. 어떻게 해결해야하는지 도와주세요

그리고 @Builder를 사용해 빌터패턴을 적용할 때 인자가 많아질 경우 아래처럼 인자가 저렇게 길어지는 것이 맞는 건가요??

    @Builder
    public ArticleResponseDto(Long id, String title, String content, LocalDateTime createdDate, LocalDateTime updatedDate, List<Hashtag> hashtags, List<Comment> comments) {
        this.id = id;
        this.title = title;
        this.content = content;
        this.createdDate = createdDate;
        this.updatedDate = updatedDate;
        this.hashtags = hashtags;
        this.comments = comments;

    }

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!