Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- CORS
- ExceptionResolver
- API
- SPOF
- RequestMappingHandlerMapping
- optimistic lock
- tracking-modes
- HandlerMethod
- #@Transacional
- assertJ
- TDZ
- CQS
- wrapper class
- Transaction
- generic type
- pessimistic lock
- COPYOFRANGE
- 역정규화
- 벌크연산
- Generic method
- cross-cutting concerns
- 프로그래머스
- Java
- demand paging
- propagation
- NestJS 요청흐름
- 단어변환
- type eraser
- IllegalStateException
- hoisting
Archives
- Today
- Total
jingyulog
QueryDSL 5.0 - fetchResults(), fetchCount() Deprecated 본문
🔎 deprecated 된 이유
- fetchResults()와 fetchCount()는 개발자가 작성한 select 쿼리를 기반으로 count 용 쿼리를 내부에서 만들어서 실행한다.
- 하지만 이게 단순한 쿼리에서는 잘 동작하지만, 복잡한 쿼리에서는 제대로 동작하지 않는다.
- 따라서 count 쿼리가 필요하면 별도로 작성해야 한다.
💻 count 쿼리 예제
List<Item> content = queryFactory
.selectFrom(item)
.where(regDtsAfter(itemSearchDto.getSearchDateType()),
searchSellStatusEq(itemSearchDto.getSearchSellStatus()),
searchByLike(itemSearchDto.getSearchBy(), itemSearchDto.getSearchQuery()))
.orderBy(item.id.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
JPAQuery<Long> countQuery = queryFactory
.select(item.count())
.from(item)
.where(regDtsAfter(itemSearchDto.getSearchDateType()),
searchSellStatusEq(itemSearchDto.getSearchSellStatus()),
searchByLike(itemSearchDto.getSearchBy(), itemSearchDto.getSearchQuery()));
return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchOne);'Tech > JPA' 카테고리의 다른 글
| QueryDSL에서 fetchResults()가 deprecated된 이유 (0) | 2023.04.30 |
|---|---|
| QueryDSL의 BooleanExpression (0) | 2023.04.30 |
| Spring Data Jpa 사용자 정의 리포지토리 사용법 (0) | 2023.04.30 |
| Auditing을 이용한 엔티티 공통 속성 공통화 (0) | 2023.04.30 |
| 지연로딩 vs 즉시로딩 (0) | 2023.04.27 |
