将Spring Boot 2.5.2升级到2.6.3会破坏所有基于投影的JPA查询 [英] Upgrading Spring Boot 2.5.2 to 2.6.3 breaks all projection based JPA queries
本文介绍了将Spring Boot 2.5.2升级到2.6.3会破坏所有基于投影的JPA查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试将应用程序的Spring Boot从2.5.2升级到2.6.3时,所有基于投影的JpaRepository查询都无法生成,并显示以下信息:
......
......
......
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.Optional com.misc.project.ProjectRepository.getProjectionByIdAndField(java.lang.String,java.lang.String)! null
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:96)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:113)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:254)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:87)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:102)
... 85 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:181)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:152)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.complete(JpaQueryCreator.java:59)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.<init>(PartTreeJpaQuery.java:217)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:92)
... 89 common frames omitted
方法如下:
Optional<SomeProjection> getProjectionByIdAndField(String id, String field);
投影基于接口,如下所示:
public interface SomeProjection {
Long getSomething();
}
如果我用@Query手动编写查询,它将移动到下一个投影。有没有什么方法可以解决这个问题,而不必为所有基于投影的JPA方法手动编写查询?
我在此找不到任何提及此问题的内容: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes#upgrading-from-spring-boot-25我发现他们在以下内容中提到了对预测的一些改进: https://github.com/spring-projects/spring-data-commons/wiki/Release-Train-2021.1-%28Q%29-Release-Notes#jdbc.projections
但不涉及破坏旧版本。
推荐答案
这是bug introduced in Spring Data JPA 2.6.1。升级到Spring Boot 2.6.4以获取包含修补程序的Spring Data JPA版本。
这篇关于将Spring Boot 2.5.2升级到2.6.3会破坏所有基于投影的JPA查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文