Open Session In View (ARCH4067)
هذا المحتوى غير متوفر بلغتك بعد.
Key java.orm.open-session-in-view · Severity warning · Category orm
Dereferencing lazy associations in the view/serialization layer (Open Session in View) keeps the DB session open and produces hidden N+1. Load the data in the service layer inside a transaction.
Incorrect
Section titled “Incorrect”@GetMapping("/orders")public List<Order> list() { return orderRepository.findAll(); // lazy items -> loaded during JSON serialization}// spring.jpa.open-in-view=trueCorrect
Section titled “Correct”@GetMapping("/orders")public List<OrderDto> list() { return orderService.findAllWithItems(); // fetch inside transaction + DTO}// spring.jpa.open-in-view=falseDisable open-in-view; load lazy data in the service/transaction layer and return DTOs.