title: Named Entity Graph Sub-Subgraph
body: <p>I am new to JPA 2.1 and started using only recently Named Entity Graphs. For my project I am mapping the following relation in JPA 2.1:</p>
  <p><strong>Order -&gt; OrderDetail -&gt; Product -&gt; ProductLine</strong></p>
  <h1>The question:</h1>
  <p>I want to instruct JPA to join and fetch properly all the needed data. So far this works flawlessly for <strong>Order -&gt; OrderDetail -&gt; Product</strong> but I have not managed so far to add a Sub-Sub Graph in order to go as deep as the ProductLine class. How do I make a subgraph of a subgraph ? Ex get the ProductLine of the Product ?</p>
  <p>Here are my entities (getters and setters omitted):</p>
  <p><strong>Order</strong></p>
  <pre><code>@Entity
  @Table(name=&quot;ORDERS&quot;)
  @NamedEntityGraph(
      name = &quot;graph.Order.details&quot;,
      attributeNodes = {
          @NamedAttributeNode(value = &quot;details&quot;, subgraph = &quot;graph.OrderDetail.product&quot;)
      },
      subgraphs = {
          @NamedSubgraph(name = &quot;graph.OrderDetail.product&quot;, attributeNodes = @NamedAttributeNode(&quot;product&quot;))
      }
  )
  
  public class Order implements Serializable{
    @Id
    @Column(name = &quot;orderNumber&quot;)
    private Long number;
  
    @Column(name = &quot;orderDate&quot;)
    private Date date;
  
    @OneToMany(mappedBy = &quot;order&quot;)
    private List&lt;OrderDetail&gt; details;
  }
  </code></pre>
  <p><strong>OrderDetail</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;orderdetails&quot;)
  public class OrderDetail implements Serializable{
  
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = &quot;orderNumber&quot;)
     @Id
     private Order order;
  
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = &quot;productCode&quot;, nullable = false)
     @Id
     private Product product;
  
     @Column(name = &quot;orderLineNumber&quot;)
     private int lineNumber;
  
     @Column(name = &quot;quantityOrdered&quot;)
     private int quantity;
  </code></pre>
  <p><strong>Product</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;products&quot;)
  class Product {
      @Column(name = &quot;productCode&quot;)
      @Id
      private String code;
  
      @Column(name = &quot;quantityInStock&quot;)
      public int quantity;
  
      @ManyToOne
      @JoinColumn(name = &quot;productLine&quot;)
      private ProductLine line;
  </code></pre>
  <p><strong>ProductLine</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;productlines&quot;)
  public class ProductLine {
      @Id
      @Column(name = &quot;productLine&quot;)
      private String line;
  
      @Column
      private String textDescription;
  </code></pre>