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?
答案 0 :(得分:1)
Spring Data尝试选择那些实际使用的部分是最好的。
在您的情况下,它实际上应该只使用自定义SQL语句选择这两个值。
如果您的界面包含一个集合,这不起作用(没有相当复杂的查询逻辑),因此Spring Data会依赖于选择完整实体并提取投影所需的值。或者至少它会once this issue is merged。
您始终可以通过检查日志中生成的SQL来验证此行为。