我有一个仓库:
public interface MilestoneRepository extends JpaRepository<Milestone,Date> {
@Query("select m from Milestone m where m.date <= :date order by m.date desc")
Page<Milestone> findLeftClosest(@Param("date") Date date, Pageable pageable);
}
像上面定义的那样是可以正常工作的,但是如果我交换参数顺序:
public interface MilestoneRepository extends JpaRepository<Milestone,Date> {
@Query("select m from Milestone m where m.date <= :date order by m.date desc")
Page<Milestone> findLeftClosest(Pageable pageable, @Param("date") Date date);
}
在初始化上下文时,我遇到了以下异常(最有意思的根本原因):
Caused by: java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
at org.springframework.util.Assert.isTrue(Assert.java:65)
at org.springframework.data.repository.query.Parameters.assertEitherAllParamAnnotatedOrNone(Parameters.java:265)
at org.springframework.data.repository.query.Parameters.<init>(Parameters.java:85)
at org.springframework.data.jpa.repository.query.JpaParameters.<init>(JpaParameters.java:43)
at org.springframework.data.jpa.repository.query.JpaQueryMethod.createParameters(JpaQueryMethod.java:284)
at org.springframework.data.jpa.repository.query.JpaQueryMethod.createParameters(JpaQueryMethod.java:51)
at org.springframework.data.repository.query.QueryMethod.<init>(QueryMethod.java:70)
at org.springframework.data.jpa.repository.query.JpaQueryMethod.<init>(JpaQueryMethod.java:79)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:69)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:304)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:84)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 59 more
我觉得这看起来像一个 bug。我的感觉是正确的吗?有人知道这个问题是否已经报告过了吗?或者也许这个行为在某个地方被记录下来并且是合理的?
spring-data-jpa 的版本:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>