<aside> ❗

OSIV - Open Session In View

image.png

→ 스프링 부트 실행 시 WARN 로그를 남기는 이유가 있다.

 WARN 37102 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : 
 spring.jpa.open-in-view is enabled by default. Therefore, 
 database queries may be performed during view rendering. 
 Explicitly configure spring.jpa.open-in-view to disable this warning

[Open Session In View - true]

[장점]

[단점]

image.png

<aside> ❗

커멘드와 쿼리 분리

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class OrderQueryService {

	private final OrderService orderService;

	public List<OrderDto> orderV2() {
        List<Order> orders = orderRepository.findAllByString(new OrderSearch());
        List<OrderDto> collect = orders.stream().map(o -> new OrderDto(o)).collect(toList());
        return collect;

    }
}
@GetMapping("/api/v2/orders")
public List<OrderDto> orderV2() {
	return orderQueryService.orderV2();
}

[참고]

[기타]

컨트롤러 → 도메인 서비스 → 애플리케이션 서비스 → 리포지토리

</aside>