title: Implementing Pagination using entity manager in spring
body: <p>How can I implement pagination in Spring + hibernate project ?
  Following is the code. I will get PageRequest object and I want to return Page of item </p>
  
  <pre><code> @Repository
      public class ItemRepository {
  
        @PersistenceContext
        EntityManager entityManager;
  
        public Page&lt;Item&gt; findItems(PageRequest pageRequest) {
          // TODO: Implement me
          return new Page&lt;&gt;(new ArrayList&lt;&gt;(), 0, 0);
        }
      }
  
  
      public class PageRequest {
  
        private final int count;
        private final int pageNumber;
  
        public PageRequest(int pageNumber, int count) {
          assert pageNumber &gt;= 0;
          assert count &gt; 0;
  
          this.pageNumber = pageNumber;
          this.count = count;
        }
  
        public int getCount() {
          return count;
        }
  
        public int getPageNumber() {
          return pageNumber;
        }
      }
  </code></pre>