java - spring data @query 和 projection 应该只选择需要的字段,但情况并非如此
问题描述
假设我有一个实体(简化)
@Entity
FooEntity {
long id;
String name;
int age;
boolean deleted;
}
我想使用弹簧投影只选择这个实体的 id 和 name 字段
所以我创建了第一个接口和实现它的类
public interface DictionaryInterface {
Long getId();
String getName();
}
@Value
class DictionaryObject implements DictionaryInterface {
Long id;
String name;
}
然后我使用使用投影接口的方法创建了存储库接口
<T> List<T> findByDeleted(boolean deleted, <Class<T> type);
并尝试了两次调用并查看了生成的 sql
findByProjection(false, DictionaryInterface.class)
// here sql select includes all fields even those that were not needed (age field)
findByProjection(false, DictionaryObject.class) ->
// here sql select includes only id and name fields
我从阅读 spring 数据文档的理解是行为应该是相同的,我必须只选择需要的字段,但我清楚地看到它不起作用
我哪里错了?
解决方案
推荐阅读
- sql - SQL server 从周数和年份检索周开始日期和周结束日期
- java - PDFBox - 从 Java 刷新嵌套的 PDComboBox
- javascript - JavaScript 中的持久暗模式
- java - Remove string after second colon in Java
- spring - 春季 5.2.8 中的 log4j xml 配置
- c - Arduino用引脚计算
- javascript - Typescript:基于类型的可选方法参数
- unity3d - 制作同一应用程序的免费和高级版本是制作一个应用程序还是制作两个应用程序更好?
- regex - 在bash中删除由多字符分隔符分割的字符串的特定部分
- c - 错误:从不兼容的类型'const char *'分配给'char'。即使我没有将字符串定义为常量