<aside> 1️⃣ 에러사항
</aside>
아래와 같은 상황에서 댓글 아래 대댓글이 달린 댓글을 삭제하기를 누르면 에러가 나왔다.
에러 메시지
{"errorMessage":"could not execute statement [Cannot delete or update a parent row: a foreign key constraint fails (profile.board_sub_comment, CONSTRAINT FK_BOARD_SUB_COMMENT_board_comment_id_BOARD_COMMENT_board_commen FOREIGN KEY (board_comment_id) REFERENCES board_comment (board_comment_id) ON)] [delete from board_comment where board_comment_id=?]; SQL [delete from board_comment where board_comment_id=?]; constraint [null]"}
<aside> 1️⃣ 해결
</aside>
@ToString.Exclude
@OneToMany(mappedBy = "boardComment")
private List<BoardSubComment> boardSubComments = new ArrayList<>(); // 대댓글
@ToString.Exclude
@OneToMany(mappedBy = "boardComment", cascade = CascadeType.ALL)
private List<BoardSubComment> boardSubComments = new ArrayList<>(); // 대댓글