상기의 글에서 depth 는 필요 없다고 함.
NumberExpression<Long> otherwise = new CaseBuilder().when(courseComment.rootCommentId.isNull()) .then(courseComment.id) .otherwise(courseComment.rootCommentId);
queryDsl의 CaseBuilder를 사용하여 부모 아이디가 null인(즉, 루트 코멘트일 경우) 코멘트 아이디를, 부모 아이디가 null이 아닐경우(즉, 대댓글일 경우) 부모 댓글의 아이디로 순서정렬이 되게 했고
List<CourseComment> commentList = jpaQueryFactory.select(courseComment) .from(courseComment) .leftJoin(courseComment.course, QCourse.course).fetchJoin() .where(QCourse.course.id.eq(courseId)) .orderBy(otherwise.asc()) //요기 .orderBy(courseComment.seq.asc()) //그 다음 시퀀스대로 정렬 .offset(pageable.getOffset()) .limit(pageable.getPageSize()+ 1) .fetch();
상기의 방식으로 작성하니 잘 되었음.
우리는 작성 순서대로 댓글의 아이디가 증가하므로 이러한 방식을 사용했고, 다른 방법이나 타입으로 아이디가 생성될 경우에는 다른 방법을 사용해야함.
추가 - seq말고 createAt 으로 해도 동작이 잘 되며 동시성 이슈도 어느정도 해결될것 같음
= seq 필요없어서 제거함.