title: Spring data JPA Specifications - @OneToMany dependency
body: <p>i have a problem with getting List from entity Person using Spring data JPA specifications (because of pagination). I need to get all notes by person but dependency between these two entities is on Person side. I don't know how to create my Predicate because Note doesn't contain any attribute related to Person.</p>
  
  <p>I simply can get List with Persons getter but i can't use this way because i need returned data paginated.</p>
  
  <pre><code>@Entity
  public class Person implements Serializable {
  
      @Id
      private Long personId;
  
      @OneToMany
      @JoinColumn(name = "personId")
      private List&lt;Note&gt; notes;
  
  }
  
  @Entity
  public class Note implements Serializable {
  
      @Id
      private Long noteId;
  }
  </code></pre>
  
  <p>Normally, I would write something like this, but i don't have an attribute person in Note and database can't be remapped at this stage. </p>
  
  <pre><code>public static Specification&lt;Note&gt; notesByPerson(final Long personId) {
          return new Specification&lt;Note&gt;() {
              @Override
              public Predicate toPredicate(final Root&lt;Note&gt; root, final CriteriaQuery&lt;?&gt; query,
                      final CriteriaBuilder builder) {
  
                  final Path&lt;Person&gt; per = root.&lt;Person&gt; get("person");
  
                  return builder.equal(per.&lt;Long&gt; get("personId"), personId);
  
              }
          };
      }
  </code></pre>
  
  <p>Thank you,
  Zdend</p>