Aller au contenu

Select Star Over Fetch (ARCH4066)

Ce contenu n’est pas encore disponible dans votre langue.

Key java.orm.select-star-over-fetch · Severity info · Category orm

Fetching the full entity when only a few fields are used inflates row width and serialization cost. Use a DTO projection.

@Query("SELECT u FROM User u") // all columns
List<User> findAll();
findAll().forEach(u -> emails.add(u.getEmail())); // only email needed
@Query("SELECT new com.app.EmailView(u.id, u.email) FROM User u")
List<EmailView> findEmails();

Use a DTO/projection query that selects only the required fields.