Performance: @Query for custom JPQL
This affects database query execution time and how quickly data is fetched and rendered on the page.
Jump into concepts and practice - no test required
@Query("SELECT u FROM User u WHERE u.status = :status") List<User> findUsersByStatus(@Param("status") String status);
@Query("SELECT u FROM User u")
List<User> findAllUsers();| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fetching all data without filters | N/A (server-side) | N/A | High due to large data | [X] Bad |
| Fetching filtered data with JPQL @Query | N/A (server-side) | N/A | Lower due to smaller data | [✓] Good |
@Query annotation in Spring Data JPA?@Query in a Spring Data JPA repository interface?@Query("SELECT u FROM User u WHERE u.age > :minAge")
List<User> findUsersOlderThan(@Param("minAge") int minAge);findUsersOlderThan(30)?@Query("SELECT u FROM User u WHERE u.email = :email")
List<User> findByEmail(String email);@Query to find all users whose name contains a given substring (case insensitive). Which of the following method definitions correctly achieves this?