Complete the association annotation to fetch associated customers eagerly when fetching orders.
@ManyToOne(fetch = [1])
private Customer customer;Using FetchType.EAGER ensures that related entities are loaded immediately, preventing the N+1 query problem.
Complete the JPQL query to fetch orders with customers using a join fetch to avoid N+1 queries.
SELECT o FROM Order o [1] JOIN FETCH o.customerUsing INNER JOIN FETCH fetches orders and their customers in one query, avoiding N+1 queries.
Fix the error in the repository method to prevent N+1 queries by adding the correct annotation.
@Query("SELECT o FROM Order o [1] JOIN FETCH o.customer") List<Order> findAllOrdersWithCustomers();
The INNER JOIN FETCH annotation in the query ensures orders and customers are fetched together, avoiding N+1 queries.
Fill both blanks to define a Spring Data JPA method that fetches orders with customers eagerly.
List<Order> findAllBy[1]Fetch[2]();
The method name findAllByCustomerFetchEagerly suggests fetching orders with customers eagerly, helping avoid N+1 queries.
Fill all three blanks to complete the code that uses EntityGraph to solve the N+1 query problem.
@EntityGraph(attributePaths = {"[1]"})
List<Order> findAllWith[2]();
// Usage:
List<Order> orders = orderRepository.[3]();Using @EntityGraph(attributePaths = {"customer"}) with method findAllWithCustomers() fetches orders with customers eagerly, avoiding N+1 queries.