【发布时间】:2018-07-09 23:05:25
【问题描述】:
我正在尝试在 JpaSpecificationExecutor 的 findAll(Specification<T> spec, Pageable pageable) 上获取一些数据。
我的规格是:
public static Specification<Report> isTemplate(boolean isTemplate) {
return (root, query, cb) ->{
root.fetch("entity1");
root.fetch("entity2");
root.fetch("entity3");
root.fetch("entity4");
root.fetch("entity5");
return cb.equal(root.get("isTemplate"), isTemplate);
};
}
其中报告有 5 个子表(实体 1...),它们与报告具有一对一的关系。
下面是他的一个关系的 getter 示例:
@OneToOne(fetch = FetchType.LAZY, mappedBy = "report")
@Fetch(FetchMode.JOIN)
public Entity1 getEntity1() {
return this.entity1;
}
现在,当我使用我的规格致电 List<T> findAll(Specification<T> spec) 时,一切正常。但是当我调用 Page<T> findAll(Specification<T> spec, Pageable pageable) 时,到达计数查询失败时会出现下一个异常:
“例外”: "org.springframework.dao.InvalidDataAccessApiUsageException", “消息”:“org.hibernate.QueryException:查询指定连接 正在获取,但获取的关联的所有者不存在 选择列表... [select count(generatedAlias0) from com.xxx.yyy.editor.entity.Report as generatedAlias0 inner join fetch generatedAlias0.report1 as generatedAlias1 内连接获取 generatedAlias0.report2 as generatedAlias2..."
任何其他人都面临这个问题或知道为什么会发生这种情况。
我使用的是 Spring Boot 1.5.9。
提前谢谢你。
PD。我正在使用 fetch 在一个查询中获取所有关系。
【问题讨论】:
标签: java count spring-data-jpa fetch specifications