Early Materialization (ARCH4056)
Ce contenu n’est pas encore disponible dans votre langue.
Key java.orm.early-materialization · Severity warning · Category orm
Filtering or sorting in memory after materializing the query to a list moves work that belongs in the database into the application. Push the predicate into the query.
Incorrect
Section titled “Incorrect”List<Order> all = orderRepository.findAll();List<Order> paid = all.stream() .filter(o -> o.getStatus() == PAID) // whole table in memory .collect(toList());Correct
Section titled “Correct”List<Order> paid = orderRepository.findByStatus(OrderStatus.PAID);Push filtering/ordering/aggregation into the database via WHERE/ORDER BY, not in memory.