title: RepositoryItemReader: java.util.ArrayList cannot be cast to org.springframework.data.domain.Page
body: <p>I'm setting up an ItemRepositoryReader for the reader in a spring batch step. I wanna use findByScenarioBetween method which takes two parameters, min, and max.</p>
  
  <p><strong>My repo</strong></p>
  
  <pre><code>public interface FuneralPricingRepository extends JpaRepository&lt;FuneralPricing, Long&gt; {
  
      @Query("select p from FuneralPricing p where p.scenario between ?1 and ?2")
      List&lt;FuneralPricing&gt; findByScenarioBetween(Long min, Long max, Pageable pageable);
  
  
  }
  </code></pre>
  
  <p>My Reader</p>
  
  <pre><code>  @Bean
    @StepScope
    public ItemReader&lt;FuneralPricing&gt; funeralPricingRepositoryReader(
            @Value("#{jobParameters[start]}") Long start,
            @Value("#{jobParameters[end]}") Long end) {
      RepositoryItemReader&lt;FuneralPricing&gt; repositoryItemReader = new RepositoryItemReader&lt;&gt;();
      repositoryItemReader.setPageSize(10);
      repositoryItemReader.setSort(funeralPricingSort());
      repositoryItemReader.setRepository(funeralPricingRepository);
      repositoryItemReader.setMaxItemCount(100);
      repositoryItemReader.setMethodName("findByScenarioBetween");
      List parameters = new ArrayList();
      parameters.add(start);
      parameters.add(end);
      repositoryItemReader.setArguments(parameters);
      return repositoryItemReader;
    }
  </code></pre>
  
  <p>When I use findAll it's working fine. But then I don't wanna read all row every time. I don't know if I am missing something in my reader!, Thanks.</p>
  
  <pre><code>java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.springframework.data.domain.Page at org.springframework.batch.item.data.RepositoryItemReader.doPageRead(RepositoryItemReader.java:208) at org.springframework.batch.item.data.RepositoryItemReader.doRead(RepositoryItemReader.java:153) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:88) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) at com.sun.proxy.$Proxy120.read(Unknown Source) at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91) at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157) at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:116) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:110) at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) at org.sp
  </code></pre>