title: How to filter parent object which has list of children and a child has list of grand children and by matching property of grand children
body: <p>Object hierarchy is as follow. </p>
  
  <p>CoverCategory has multiple Covers and a Cover has multiple SubCovers.
  Let says that in coding</p>
  
  <h1>CoverCategory</h1>
  
  <pre><code>@Entity
  public class CoverCategory {
  
  @Id
  private Long id;
  
  @OneToMany
  List&lt;Cover&gt; coverList;
  
  }
  </code></pre>
  
  <h1>Cover</h1>
  
  <pre><code>@Entity
  public class Cover {
  
   @Id
   private Long id;
  
   @ManyToOne
   private CoverCategory coverCategory;
  
   @OneToMany
   private List&lt;SubCover&gt; subCoverList;
  
  }
  </code></pre>
  
  <h1>Sub Cover</h1>
  
  <pre><code>@Entity
  public class SubCover {
  
         @Id
         private Long id;
  
         @ManyToOne
         private Cover cover;
  
         private String name;
  }
  </code></pre>
  
  <p>Here what I am try to do is select all the cover categories which has sub cover name "subcover1"</p>
  
  <p>I tried to write the code as follows</p>
  
  <pre><code>String name = "subcover1";
  Session session = getCurrentSession();
  CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
  CriteriaQuery&lt;CoverCategory&gt; creteriaQuery = criteriaBuilder.createQuery(CoverCategory.class);
  Root&lt;CoverCategory&gt; root = creteriaQuery.from(CoverCategory.class);
  creteriaQuery.select(root).where(criteriaBuilder.equal(root.get("coverList").get("subCoverList").get("name"),name));
  Query&lt;CoverCategory&gt; query = session.createQuery(creteriaQuery);
  List&lt;CoverCategory&gt; results = query.getResultList();
  </code></pre>
  
  <p>But it gives me following exception</p>
  
  <pre><code>org.springframework.dao.InvalidDataAccessApiUsageException: Illegal attempt to dereference path source [null.coverList] of basic type; nested exception is java.lang.IllegalStateException: Illegal attempt to dereference path source [null.coverList] of basic type  
  </code></pre>
  
  <p>Can someone tell me how to do this properly. Thanks in advance.
  Only need to be done in criteria builder</p>