jpashop : get data api v3 (fetch join)

This commit is contained in:
kim
2021-01-26 20:52:42 +09:00
parent a2b9015d04
commit b8829b9dc8
3 changed files with 21 additions and 5 deletions

View File

@@ -11,9 +11,9 @@ public class JpashopApplication {
public static void main(String[] args) {
SpringApplication.run(JpashopApplication.class, args);
}
@Bean
Hibernate5Module hibernate5Module() {
return new Hibernate5Module();
// .configure(Hibernate5Module.Feature.FORCE_LAZY_LOADING, true);
}
// @Bean
// Hibernate5Module hibernate5Module() {
// return new Hibernate5Module();
//// .configure(Hibernate5Module.Feature.FORCE_LAZY_LOADING, true);
// }
}

View File

@@ -46,4 +46,12 @@ public class OrderSimpleApiController {
.map(SimpleOrderDto::new)
.collect(Collectors.toList());
}
@GetMapping("/api/v3/simple-orders")
public List<SimpleOrderDto> ordersV3() {
List<Order> orders = orderRepository.findAllWithMemberDelivery();
return orders.stream()
.map(SimpleOrderDto::new)
.collect(Collectors.toList());
}
}

View File

@@ -95,4 +95,12 @@ public class OrderRepository {
.setMaxResults(1000) // 최대 1000건건
.getResultList();
}
public List<Order> findAllWithMemberDelivery() {
return em.createQuery(
"select o from Order o" +
" join fetch o.member m" +
" join fetch o.delivery", Order.class)
.getResultList();
}
}