我是Spring Data的新手。我知道我可以动态地使用JPA Specification<T>
(其中T是我的实体)来构造lambda样式的where谓词,并且JHipster具有许多功能,可以根据用户输入动态地构建where谓词。我已成功将这样的谓词集成到简单的根实体查询(select [something] from [RootEntity] item
)中。
现在,我的问题是我的查询必须跨越联接中不相关的实体,因此过滤器也必须如此。
- 如前所述,某些实体没有映射关系,并且必须没有映射关系
- 查询映射到DTO
- 查询必须可分页
- 某些过滤器是固定的,并通过代码注入
- 用户将为所有三个实体的大多数属性提供过滤器输入
- 对于这个问题,我仍然不清楚查询
HQL查询的结构类似于
select A.field as field,... B.field as field,... C.field as field
from FirstEntity A left outer join
SecondEntity B on (A.something = B.something) left outer join
ThirdEntity C on (C.something = ?.something)
where ????
我还没有尝试过 ,主要是因为签名选择会影响其他所有内容。
我坚持设计方法。
我想问一下当查询跨越不相关的实体时如何正确使用Specification
。
我不知道Spring Data是否接受类似的东西
@Query("[my hql text as above,with aliases]")
Page<DTO> doTheQuery(Specification<FirstEntity> firstFilter,Specification<SecondEntity> secondFilter,Specification<ThirdEntity> thirdFilter,Pageable pageable);
在上面的示例中,有三个不同的过滤器。
或
@Query("[my hql text as above,with aliases]")
Page<DTO> doTheQuery(Specification<?> singleFilter,Pageable pageable);