Java spring数据JpaRepository方法问题中的Pageable和@Param
我有以下存储库:Java spring数据JpaRepository方法问题中的Pageable和@Param,java,jpa,spring-data,spring-data-jpa,Java,Jpa,Spring Data,Spring Data Jpa,我有以下存储库: 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, Page
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 milestorepository扩展了JpaRepository{
@查询(“从里程碑m中选择m,其中m.date这确实是一个bug。我已经归档并修复了它,它将成为Spring数据共享1.7.3、1.8.1和1.9 M1。这是一个bug。我已经为您归档了,即将修复:)。将在修复后回复答案。这是一项即时服务:)不希望被打扰,但我仍然想知道检查是否会失败,原因如下:User validWithPageTableSecond(字符串用户名,可分页)
没有机会测试它,但仅仅看一下代码,我认为它会失败。我不确定它是否真的应该?Pageable/Sortable是否可以与非命名参数混合?实际上它不应该(并且下游测试都仍然有效)。请注意,断言方法会迭代可绑定参数(哪些规则Pageable
和Sort
out)。之前的0作为参数索引的硬检查是这里的问题。谢谢,应该也检查测试。这在spring data 1.7.0中仍然是一个问题?请参阅
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
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>