title: How to find out if end of page size has reached in spring jpa
body: <p>I am calling ajax on scroll. When ever the html page scroll has reached to end of window, I am requesting data using spring jpa but the problem is even after fetching all the records, when I scroll up and down, the ajax request is sent and data is re-fetched again.</p>
  
  <p>How do I get around this?</p>
  
  <p>Ajax request on scroll:</p>
  
  <pre><code>window.onload = function(){
      var win = $(window);
      // Each time the user scrolls
      win.scroll(function() {
          console.log('scroll reached the end. Loading new data');
  
          if (DataMixin.data.processing)
          return false;
          // End of the document reached?
          if ($(document).height() - win.height() == win.scrollTop()) {
  //            $('#loading').show();
              DataMixin.data.processing = true;
              DataMixin.data.size++;
              DataMixin.get_data_page_load();
          }
      });
  }
  </code></pre>
  
  <p>Spring jpa:</p>
  
  <pre><code>@RequestMapping(path = "/get_data_on_page_load", method = RequestMethod.GET)
  public ResponseEntity get_data_on_page_load(@RequestParam(value="page") int page, @RequestParam(value="size") int size) throws Exception {
      String role = "ROLE_USER";
      Page&lt;TopicBean&gt; topics = topicService.findAllByPage(new PageRequest(page, size));
      List&lt;CommentLikes&gt; likes = commentLikesService.findAll();
      return new ResponseEntity(new LoginDataBean( topics, role, "", likes),  HttpStatus.OK);
  }
  </code></pre>
  
  <p>pom:</p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt; 
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;version&gt;9.4-1203-jdbc42&lt;/version&gt;
      &lt;/dependency&gt; 
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-log4j2&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.mobile&lt;/groupId&gt;
          &lt;artifactId&gt;spring-mobile-device&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;io.jsonwebtoken&lt;/groupId&gt;
          &lt;artifactId&gt;jjwt&lt;/artifactId&gt;
          &lt;version&gt;0.7.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.validation&lt;/groupId&gt;
          &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
          &lt;version&gt;1.1.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>Unable to find <code>hasNextPage()</code> method for pagination</p>
  
  <p><strong>Update:</strong> Checking the interface <code>Page</code> which extends <code>Slice</code> interface has only these methods:</p>
  
  <pre><code>package org.springframework.data.domain;
  
  public interface Pageable {
  
      public int getPageNumber();
  
      public int getPageSize();
  
      public int getOffset();
  
      public Sort getSort();
  
      public Pageable next();
  
      public Pageable previousOrFirst();
  
      public Pageable first();
  
      public boolean hasPrevious();
  }
  </code></pre>
  
  <p>I don't see <code>hasNextPage()</code> method. Why?</p>