QuerydslBinderCustomizer 在 Spring Data JPA 2.0.7 中不起作用

编程入门 行业动态 更新时间:2024-10-27 16:24:44
本文介绍了QuerydslBinderCustomizer 在 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() 和 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 并转换为类似的方法是可以的(我不知道是否/知道这可能),但即使是可能的,这听起来也不是一个好方法解决方法.

文档:docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.web.binding

我遵循的教程之一: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: docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.web.binding

One of tutorials that I have followed: 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 中不起作用

本文发布于:2023-11-22 17:24:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618344.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   Spring   QuerydslBinderCustomizer   Data   JPA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!