将 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 启动从 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 启动从 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 版本。