@Query("select l from Lecture l left join fetch l.professor where l.professor.state = :state" +
            " and l.professor.memberName like %:name%" +
            " and l.semester = :semester")

스프링 데이터 JPA에서 fetch join이 들어간 경우 Count 쿼리를 정상적으로 만들지 못한다.

따라서 이 경우 @Query에 countQuery를 분리하여 작성해야 된다.

@Query(value = "select l from Lecture l left join fetch l.professor where l.professor.state = :state" +
            " and l.professor.memberName like %:name%" +
            " and l.semester = :semester",
            countQuery = "select count(l) from Lecture l where l.professor.state = :state" +
                    " and l.professor.memberName like %:name%" +
                    " and l.semester = :semester")

(@EntityGraph를 사용하는 경우에는 Count 쿼리를 정상적으로 만들어낼 수 있다는데 잘 모르겠다.)

Spring-Data FETCH JOIN with Paging is not working