Reputation: 2358
I am using Spring Boot with Spring Data JPA. In many places in my query, I am using Projections since I don't want all columns to be fetched from DB.
Projections are interface based like :
public interface VeryBasicProjection {
String getTitle();
String getUrl();
}
So my question is whether it actually fetches just two columns or it fetches all columns and then just set these two columns in projections?
Upvotes: 1
Views: 565
Reputation: 81988
Spring Data tries it's best to just select those parts that are actually used.
In your case, it actually should just select the two values using a custom SQL statement.
If your interface contains a collection this does not work (without a rather complex query logic), so Spring Data falls back on selecting the complete entity and extracting the values required for the projection. Or at least it will once this issue is merged.
You can always verify this behavior by checking the generated SQL in the logs.
Upvotes: 1