[JPQL vs QueryDSL]
1. JPQL은 실행후에야 문법 오류를 알 수 있지만
, QueryDSL은 컴파일 시점에 문법 오류를 발견할 수 있다.
2. JPQL은 문자열이지만 QueryDSL은 코드로 작성한다.
3. QueryDSL은 IDE의 도움으로 코드 자동완성 기능을 사용할 수 있다.
갑작스럽게 JPA로 개발은 맡게 되어 정리를 해보았다.
[Controller]
▶ URL Mapping과 Service 호출
[Service]
▶ Repository의 Method 호출
[Repository]
▶ Interface로써 DefaultJapRespository와 Repository 상속
@Repository
public interface ProductRepository extends DefaultJpaRepository<ItemEntity, Long>, ProductRepositoryCustom {
}
[RepositoryImpl]
▶ Query 호출
@Slf4j
@Component
@RequiredArgsConstructor
public class ProductRepositoryImpl implements ProductRepositoryCustom {
private final JPAQueryFactory factory;
@Override
public ProductDetailDto selectProductDetail(ProductDetailRequestModel request) {
return factory
.select(
Projections.bean(
ProductDetailDto.class
, itemEntity.id.as("itemId")
, itemEntity.categoryLarge
, itemEntity.categoryMedium
, itemEntity.categorySmall
, displayCateItemEntity.id.cateCode
...
)
)
.from(itemEntity)
.join(displayCateItemEntity).on(itemEntity.id.eq(displayCateItemEntity.id.itemId))
.leftJoin(userCEntity).on(itemEntity.makerId.eq(userCEntity.makerId))
.where(itemEntity.id.eq(request.getItemId()))
.fetchOne()
;
}
}
반응형
'Jpa' 카테고리의 다른 글
ModelMapper & MapStruct (0) | 2024.01.22 |
---|---|
Entity & Dto (0) | 2024.01.18 |
5. 연관관계 매핑 (0) | 2023.01.19 |
4. 엔티티 매핑 (0) | 2023.01.19 |
3. 영속성(Persistence) 관리 (0) | 2023.01.19 |