1. User Entity

@Id
@JsonIgnore
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long uid;

@Column(length = 20)
private String nickname;


2. Comment Entity

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long commentId;

@Column(name = "comment_text", nullable = false, columnDefinition="LONGTEXT")
private String commentText;@ManyToOne
@JoinColumn(name = "writer")
private User writer;


3. CommentMapping interface

public interface CommentMapping {
Long getComment_Id();
String getComment_Text();
User getWriter();
}

4. JPA쪽

Page<CommentMapping> getFrameCommentByBoard



=========================================




1,2번처럼 DB가 구성되어있고 Comment 테이블에 User가 FK로 들어가 있습니다.

실제 DB에는 writer | bigint(20) 로 구성되어있고 댓글을 입력한 사람의 uid가 들어가 있습니다

저 상태로 api 호출하면 아래처럼 에러가 납니다 ㅠㅠ


Could not write JSON: Projection type must be an interface!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Projection type must be an interface! (through reference chain: com.test.global.service.result.success.SuccessCommonResult3["data"]->org.springframework.data.domain.PageImpl["content"]->java.util.Collections$UnmodifiableRandomAccessList[0]->com.sun.proxy.$Proxy168["writer"])


그래서 CommentMapping에서 User를 int나 String으로 하면 에러는 없지만 DB에 들어가 있는 Uid값(숫자)이 출력됩니다ㅠㅠ

실제 필요한 데이터는 닉네임인데 writer의 데이터형을 User객체로 하면 에러가 나고 String이나 int는 uid만 나오고 ㅠㅠ 어떻게 해야 객체로 출력할 수 있나여? ㅠㅠ


https://gorokke.tistory.com/202


위 글 참고해서 코딩한건데 ㅠㅠ뭐가 문제인가요?