QuerydslBinderCustomizer 在 Spring Data JPA 2.0.7 中不起作用 [英] QuerydslBinderCustomizer not working in Spring Data JPA 2.0.7
问题描述
我正在尝试使用 QuerydslBinderCustomizer
在我的 Rest 控制器中执行 @QuerydslPredicate
的使用.
我正在使用 @Repositoy
实现来执行自定义查询并与表示查询访问级别的另一个表连接.
遵循文档
包含 QuerydslBinderCustomizer
的当前 Spring JPA 版本:spring-data-commons-2.0.7.RELEASE.jar
问题:
我正在尝试在 serviceExecution.code
字段中应用 like()
操作,但我只收到基于 eq()<的谓词/code> 和
customize
方法根本没有被调用.
我也尝试将代码放在基于接口的 Repository
中,但没有成功.
Repository
实现是这样的:
@Repository公共类 ServiceExecutionQueryRepositoryImpl 扩展 JpaQuerydslBaseRepository实现 ServiceExecutionQueryRepository、QuerydslBinderCustomizer、QuerydslPredicateExecutor{@覆盖公共无效定制(QuerydslBindings 绑定,QServiceExecution serviceExecution){bindings.bind(serviceExecution.code).first((path, value) -> path.likeIgnoreCase(StringUtils.like(value)));//断点永远不会命中这个方法.//绑定不应用于查询... 另一个绑定}}
Resource 方法调用:
@GetMapping("/service-executions")公共响应实体<页面>getAllServiceExecutions(@RequestParam(required = false) MultiValueMap参数,@QuerydslPredicate(root = ServiceExecution.class) 谓词谓词,Pageable pageable) {页面page = facade.findAll(parameters, predicate, pageable);返回新的响应实体(页面,HttpStatus.OK);}
生成的结果查询(在应用程序日志中看到)始终是这个(包括计数查询):
select o from ... where code = ?
谁能知道我可能遗漏了什么?是否与最近的 Spring Data JPA 版本有关?
详情:
是一个gradle using project for Spring Boot,配置了apt.除了这个问题,Querydsl 目前正在按预期工作.
检查每个方法上的 Predicates
并转换为类似的方法是可以的(我不知道是否/知道这可能),但即使是可能的,这听起来也不是一个好方法解决方法.
文档:https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.web.binding
我遵循的教程之一:https://spring.io/blog/2015/09/04/what-s-new-in-spring-data-release-gosling
类似问题:Spring @QuerydslPredicate 问题
QueryDsl 对地图键的网络查询字段(无效,因为它使用了以前版本的spring)编辑
似乎 QuerydslBindingsFactory
只加载绑定接口.
我正在使用带有 @NoRepositoryBean
的接口,该接口未在搜索自定义绑定的地图中列出.也许这就是 QuerydslBinderCustomizer
未被调用并添加到应用程序绑定的原因.
无论如何,我仍然不知道如何解决这个问题.
看来您只是忘记添加 ServiceExecutionQueryRepositoryImpl
作为 @QuerydslPredicate<的
bindings
参数/code> 注释:
@GetMapping("/service-executions")公共响应实体<页面>getAllServiceExecutions(@RequestParam(required = false) MultiValueMap参数,@QuerydslPredicate(root = ServiceExecution.class, bindings = ServiceExecutionQueryRepositoryImpl.class) 谓词谓词,可分页){页面page = facade.findAll(parameters, predicate, pageable);返回新的响应实体(页面,HttpStatus.OK);}
参见示例:sb-querydsl-sd-demo>
I'm trying to use the QuerydslBinderCustomizer
to perform the usage of @QuerydslPredicate
in my Rest controller.
I'm using a @Repositoy
implementation to perform customized queries and joins with another tables representing the access level for the query.
Following the documentation
Current Spring JPA version that contains QuerydslBinderCustomizer
: spring-data-commons-2.0.7.RELEASE.jar
The problem:
I'm trying to apply a like()
operation in the serviceExecution.code
field, but I only receive the predicate based on eq()
and the customize
method is not called at all.
I also try to put the code inside a interface based Repository
, without success.
The Repository
implementation is this one:
@Repository
public class ServiceExecutionQueryRepositoryImpl extends JpaQuerydslBaseRepository<Long, ServiceExecution> implements ServiceExecutionQueryRepository, QuerydslBinderCustomizer<QServiceExecution>, QuerydslPredicateExecutor<ServiceExecution> {
@Override
public void customize(QuerydslBindings bindings, QServiceExecution serviceExecution) {
bindings.bind(serviceExecution.code).first((path, value) -> path.likeIgnoreCase(StringUtils.like(value)));
// breakpoint never hit this method.
// bindings is not applied to the query
... another bindings
}
}
The Resource method call:
@GetMapping("/service-executions")
public ResponseEntity<Page<ServiceExecutionDTO>> getAllServiceExecutions(
@RequestParam(required = false) MultiValueMap<String, String> parameters,
@QuerydslPredicate(root = ServiceExecution.class) Predicate predicate, Pageable pageable) {
Page<ServiceExecutionDTO> page = facade.findAll(parameters, predicate, pageable);
return new ResponseEntity<>(page, HttpStatus.OK);
}
The resulting query generated (seen in application logs) is always this one (including count query):
select o from ... where code = ?
Can anyone know what I'm possible missing? Is something related to the recent Spring Data JPA version?
Details:
It's a gradle using project for Spring Boot, apt is configured. Except this issue, Querydsl is currently working as expected.
It's possible OK to check the Predicates
on each method and transform to a like (I don't know if / know it's possible), but even being possible it doesn't sounds like a good workaround.
Docs: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.web.binding
One of tutorials that I have followed: https://spring.io/blog/2015/09/04/what-s-new-in-spring-data-release-gosling
Similar question: Spring @QuerydslPredicate Questions
QueryDsl web query on the key of a Map field (Invalid because it uses a previous version of spring) EDIT
It seems that QuerydslBindingsFactory
is loading only interfaces for bindings.
I'm using a interface with @NoRepositoryBean
, that is not listed in the map that search for custom bindings. Maybe this the cause for the QuerydslBinderCustomizer
not being called and added to the application bindings.
Anyway, I still don't know how to fix that.
It seems you just forgot to add your ServiceExecutionQueryRepositoryImpl
as bindings
parameter of @QuerydslPredicate
annotation:
@GetMapping("/service-executions")
public ResponseEntity<Page<ServiceExecutionDTO>> getAllServiceExecutions(
@RequestParam(required = false) MultiValueMap<String, String> parameters,
@QuerydslPredicate(root = ServiceExecution.class, bindings = ServiceExecutionQueryRepositoryImpl.class) Predicate predicate,
Pageable pageable
) {
Page<ServiceExecutionDTO> page = facade.findAll(parameters, predicate, pageable);
return new ResponseEntity<>(page, HttpStatus.OK);
}
See may example: sb-querydsl-sd-demo
这篇关于QuerydslBinderCustomizer 在 Spring Data JPA 2.0.7 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!