@Query(value = "select id, name from product where name = :productName", nativeQuery = true)
Page<Product> findAllByNameWithPagination(String productName, Pageable pageable);
페이징으로 조회 할 때, 다음과 같이 기본적인 쿼리 형식으로 조회할 경우 에러가 발생할 확률이 높아진다.
@Query(value = "select id,name from product a where name = :productName", nativeQuery = true
,countQuery = "select count(*) from product where name = :productName ")
Page<Product> findAllByNameWithPagination(String productName, Pageable pageable);
countQuery 를 이용하여 총 갯수를 구한 후, 조회한다면 에러가 발생하지 않는다.
'JPA' 카테고리의 다른 글
[JPA] JPA의 페이징 - Pageable (0) | 2024.11.26 |
---|---|
[JPA] @OneToOne, 일대일 관계 (0) | 2024.02.26 |
[JPA] 값 타입 (Value Object) (0) | 2024.02.26 |
[JPA] SQL 쿼리를 활용 (0) | 2024.02.19 |
[JPA] 식별자 생성 (0) | 2024.02.19 |