OnToMany 관계의 복잡한 동적쿼리는 어떻게 해결하나요?
1728
작성한 질문수 13
@Override
public Page<?> findAllPostWithCategory3(Pageable pageable, List<Tech> techList, Category category, Place place) {
JPAQuery<PostResponseDto> query = queryFactory.
select(new QPostResponseDto(post))
.from(post)
.leftJoin(post.account, account).fetchJoin()
.where(checkCategory(category), checkPlace(place))
.leftJoin(post.techs, techs)
.where(checkTechList(techList))
.offset(pageable.getOffset())
.limit(pageable.getPageSize());
// sorting
for (Sort.Order o : pageable.getSort()) {
PathBuilder pathBuilder = new PathBuilder(post.getType(), post.getMetadata());
query.orderBy(new OrderSpecifier(o.isAscending() ? Order.ASC : Order.DESC,
pathBuilder.get(o.getProperty())));
}
List<PostResponseDto> list = query.fetch();
JPAQuery<Long> countQuery = queryFactory
.select(post.count())
.from(post)
.where(checkTechList(techList));
return PageableExecutionUtils.getPage(list, pageable, countQuery::fetchOne);
}//동적 관리
/*techList in query where*/
private BooleanExpression checkTechList (List < Tech > techList) {
return techList == null ? null : techs.tech.in(techList);
}
/*category in query where*/
private BooleanExpression checkCategory (Category category){
return category == null ? null : post.category.eq(category);
}
/*place in query where*/
private BooleanExpression checkPlace (Place place){
return place == null ? null : post.place.eq(place);
}
Post를 기준으로 account는 manyToOne이고
지금 문제가 되는것은 Tech입니다. Post와 oneToMany관계인데, 동적쿼리를 tech의 값으로 해야되서 문제가 발생합니다..
페이지네이션을 유지해야하기에, 어떻게 짜야할지 모르겠습니다. 제발 도움이나 힌트 부탁드립니다
답변 1
SpringBoot 4.X에서의 Querydsl 설정
0
109
2
querydsl 오픈소스에 대한 질문
1
84
1
예제에서의 카운트 쿼리에서 join문과 where문은 필요없지 않나요?
0
115
1
Querydsl 6.X버전에 대해서 어떻게 생각하시나요?
0
329
2
여러 테이블 조인하여 통계치를 구하고자 할 때 어떤 방법이 더 효율적일까요
1
73
1
fetchResults()는 더이상 권장되지 않는다는데 맞나요?
0
164
1
querydsl sum() 메서드 없어요.
0
163
2
build 디렉터리 생성
0
142
2
자바 ORM 표준 JPA 프로그래밍 - 기본편 듣고 바로 학습해도 괜찮을까요?
0
116
2
현재 Querydsl에서 from절 서브쿼리를 지원하나요?
0
95
1
오타 제보 드립니다.
0
74
2
벌크 연산과 flush, clear
0
78
1
Run As Intellij 로 변경시 Q타입 import 불가
0
90
1
QHello import하기 문제 발생
0
150
2
등록된 함수 보는법(H2Dialect) 질문
0
70
2
5.0부터 Querydsl은 향후 fetchCount() , fetchResult() 를 지원하지 않기로 결정했다고 하는데 이에 맞는 강의
1
201
2
[환경설정 PDF 부트 3.0이후 설명 질문] build.gradle에 compileQuerydsl을 정의하지 않은 상태에서 Gradle->Tasks->other->compileQuerydsl을 클릭하라고 하는 이유가 무엇인가요??
1
204
1
querydsl 설정 문제
0
223
2
quey dsl 설정부분
0
159
2
count 쿼리 관련 질문입니다!
0
75
1
stringtemplate를 이용하여 where절 검색 방법 질문 드립니다.
0
90
1
답변부탁드리겠습니다.
0
92
2
(OrderSpecifier)관련 내용 어디있을가요
0
67
1
중급문법 벌크연산에서
0
84
2





