title: Spring Data JPA + JpaSpecificationExecutor + EntityGraph
body: <p>(Using Spring Data JPA) I have two entities <code>Parent</code>&amp; <code>Child</code> with a OneToMany/ManyToOne bi-directional relationship between them.  I add a <a href="http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.entity-graph" rel="noreferrer"><code>@NamedEntityGraph</code></a> to the parent entity like so:</p>
  
  <pre><code>@Entity
  @NamedEntityGraph(name = "Parent.Offspring", attributeNodes = @NamedAttributeNodes("children"))
  public class Parent{
  //blah blah blah
  
  @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
  Set&lt;Child&gt; children;
  
  //blah blah blah
  }
  </code></pre>
  
  <p>Notice that the fetch type for the Parent's children is LAZY.  This is on purpose.  I don't always want to eager load the children when I'm querying an individual parent.  Normally I could use my named entity graph to eager load the children on-demand, so to speak.  But.....</p>
  
  <p>There is a specific situation where I'd like to query for one or more parents AND eager load their children.  In addition to this I need to be able to build this query programmatically.  Spring Data provides the <a href="http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#specifications" rel="noreferrer">JpaSpecificationExecutor</a> which allows one to build dynamic queries, but I can't figure out how to use it in conjunction with entity graphs for eager loading children in this specific case.  Is this even possible?  Is there some other way to eager load 'toMany entities using specifications?</p>