jpashop : 컬렉션 조회 v3 (dto 응답, fetch join, distinct)

This commit is contained in:
kim
2021-01-27 18:14:08 +09:00
parent 288d6ca162
commit ddbd688d8c
2 changed files with 18 additions and 0 deletions

View File

@@ -36,4 +36,12 @@ public class OrderApiController {
.map(OrderDto::new)
.collect(Collectors.toList());
}
@GetMapping("/api/v3/orders")
public List<OrderDto> ordersV3() {
List<Order> orders = orderRepository.findAllWithItem();
return orders.stream()
.map(OrderDto::new)
.collect(Collectors.toList());
}
}

View File

@@ -103,4 +103,14 @@ public class OrderRepository {
" join fetch o.delivery", Order.class)
.getResultList();
}
public List<Order> findAllWithItem() {
return em.createQuery(
"select distinct o from Order o" +
" join fetch o.member m" +
" join fetch o.delivery d" +
" join fetch o.orderItems oi" +
" join fetch oi.item i", Order.class)
.getResultList();
}
}