title: Spring Boot JPA Pagination Exception
body: <p>I am implementing pagination for my service where limit and offset comes as a part of request body. When I have set these values in the PageRequest at the Service level, I am getting the following error and the implementation</p>
  
  <pre><code>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:92) ~[spring-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
      at org.springframework.data.repository.query.Parameters.assertEitherAllParamAnnotatedOrNone(Parameters.java:297) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
      at org.springframework.data.repository.query.Parameters.&lt;init&gt;(Parameters.java:91) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
      at org.springframework.data.jpa.repository.query.JpaParameters.&lt;init&gt;(JpaParameters.java:43) ~[spring-data-jpa-1.11.8.RELEASE.jar:na]
      at org.springframework.data.jpa.repository.query.JpaQueryMethod.createParameters(JpaQueryMethod.java:325) ~[spring-data-jpa-1.11.8.RELEASE.jar:na]
      at org.springframework.data.jpa.repository.query.JpaQueryMethod.createParameters(JpaQueryMethod.java:53) ~[spring-data-jpa-1.11.8.RELEASE.jar:na]
      at org.springframework.data.repository.query.QueryMethod.&lt;init&gt;(QueryMethod.java:77) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
      at org.springframework.data.jpa.repository.query.JpaQueryMethod.&lt;init&gt;(JpaQueryMethod.java:89) ~[spring-data-jpa-1.11.8.RELEASE.jar:na]
      at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77) ~[spring-data-jpa-1.11.8.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.&lt;init&gt;(RepositoryFactorySupport.java:436) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
      at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263) ~[spring-data-commons-1.13.8.RELEASE.jar:na]
      at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101) ~[spring-data-jpa-1.11.8.RELEASE.jar:na]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
      ... 55 common frames omitted
  </code></pre>
  
  <p>Student Request:</p>
  
  <pre><code>{
    "name": "string",
    "paging": {
      "limit": 0,
      "startOffset": 0
    }
  }
  </code></pre>
  
  <p>Student Service:</p>
  
  <pre><code>@Service
  public class StudentService {
  
      @Autowired
      private StudentRepository studentRepository;
  
      public List&lt;Student&gt; getAllStudents(StudentRequest studentRequest) {
  
         List&lt;Student&gt; studentList = studentRepository.getAll(studentRequest,new PageRequest(studentRequest.getPaging().getStartOffset(), studentRequest.getPaging().getLimit()));
         return studentList;
      }
  }
  </code></pre>
  
  <p>Student Repository:</p>
  
  <pre><code>@Repository
  public interface StudentRepository extends CrudRepository&lt;Student, Long&gt; {
  
      @Query(value = "select o from Student  o  where (o.name = :#{#studentRequest.name} OR :#{#studentRequest.name} IS NULL ) ")
      public List&lt;Student&gt; getAll(@Param("studentRequest") StudentRequest studentRequest, PageRequest pageRequest);
  }
  </code></pre>