title: Spring Data JPA. Pagination for child entities
body: <p>I'm using Spring Data JPA with Spring boot version 1.3.6.RELEASE with in-memory database.</p>
  
  <p>I'm wondering how to <strong>paginate the child entities</strong> from a parent entity.
  Setting fetch to <strong>LAZY</strong> is not a solution for me.</p>
  
  <p>Here is the use case :</p>
  
  <ol>
  <li><em>Parent</em> has an <strong>unidirectional</strong> oneToMany relation with Child <em>entity</em>.</li>
  <li>The number of <em>Child</em> for one <em>Parent</em> can reach 100,000 (LAZY is not a solution)</li>
  <li>I don't want to fetch all the child to do the pagination (For CPU and Memory reason)</li>
  </ol>
  
  <p>Here is a code sample :</p>
  
  <pre><code>@Entity
  public class Parent{
      @Id
      private Integer id;
  
      @OneToMany
      private List&lt;Child&gt; childs;
  }
  
  @Entity
  public class Child {
      @Id
      private Integer id;
  }
  
  public interface ParentRepository extends JpaRepository&lt;Parent, Integer&gt;{}
  public interface ChildRepository extends JpaRepository&lt;Child, Integer&gt;{}
  </code></pre>
  
  <p>I've tried this in the Parent repository unsuccessfully :</p>
  
  <pre><code>Page&lt;Child&gt; findById(int id, Pageable pageable);
  </code></pre>
  
  <p>This returns a Parent entity, not a Child entity.</p>
  
  <p>Any idea how to do this ?  </p>