hibernate 使用类型. InvalidDataAccessApiUsageException进行Spring Data 查询时出错:参数值与预期类型不匹配[java.lang.Class(n/a)]

lxkprmvk  于 2023-03-30  发布在  Spring
关注(0)|答案(1)|浏览(229)

我有一个超类和两个子类。我想写一个从公共表中提取特定类记录的查询。(我使用单表Map策略)。
我的请求看起来像这样:

@Query("SELECT s FROM AbstractConcentration s WHERE type(s) = :book")
AbstractConcentration findSingle(@Param("book") Class book);

现在的例外是:

Caused by: java.lang.IndexOutOfBoundsException: Index: 0
    at java.base/java.util.Collections$EmptyList.get(Collections.java:4483)
    at org.springframework.data.repository.query.Parameter.isDynamicProjectionParameter(Parameter.java:209)
    at org.springframework.data.repository.query.Parameter.<init>(Parameter.java:63)
    at org.springframework.data.jpa.repository.query.JpaParameters$JpaParameter.<init>(JpaParameters.java:88)
    at org.springframework.data.jpa.repository.query.JpaParameters.createParameter(JpaParameters.java:58)
    at org.springframework.data.jpa.repository.query.JpaParameters.createParameter(JpaParameters.java:37)
    at org.springframework.data.repository.query.Parameters.<init>(Parameters.java:76)
    at org.springframework.data.jpa.repository.query.JpaParameters.<init>(JpaParameters.java:45)
    at org.springframework.data.jpa.repository.query.JpaQueryMethod.createParameters(JpaQueryMethod.java:363)
    at org.springframework.data.jpa.repository.query.JpaQueryMethod.createParameters(JpaQueryMethod.java:58)
    at org.springframework.data.repository.query.QueryMethod.<init>(QueryMethod.java:80)
    at org.springframework.data.jpa.repository.query.JpaQueryMethod.<init>(JpaQueryMethod.java:95)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:79)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:553)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:546)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
    at java.base/java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1054)
    at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:548)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:538)
    at java.base/java.util.Optional.map(Optional.java:265)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:538)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:317)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$3(RepositoryFactoryBeanSupport.java:286)
    at org.springframework.data.util.Lazy.getNullable(Lazy.java:141)
    at org.springframework.data.util.Lazy.get(Lazy.java:63)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:289)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:102)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1758)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1695)
    ... 22 more

我该如何解决这个问题?

qlvxas9a

qlvxas9a1#

请检查您的项目正在使用的Spring Data Commons版本(工件标识符spring-data-commons)。仅在Spring Data Commons 2.7.8和3.0.2中引入了对将Class类型的查询方法参数绑定到查询的支持。

相关问题