title: JPA Criteria API find by field nested list of entities
body: <p>I have <code>Certificate</code> class that contains list of <code>Tag</code> classes (many to many) and I have to find <code>Certificates</code> that contain certain <code>Tag</code> (by tag name)
  I'm using JPA Criteria API but cannot do this..</p>
  <pre><code>@Entity
  @Table(name = &quot;gift_certificate&quot;)
  public class Certificate {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
      private String name;
      private String description;
      private BigDecimal price;
      private Integer duration;
      @Column(name = &quot;create_date&quot;)
      private LocalDateTime createDate;
      @Column(name = &quot;last_update_date&quot;)
      private LocalDateTime lastUpdateDate;
      @ManyToMany
      @JoinTable(name = &quot;gift_certificate_tag&quot;,
              joinColumns = @JoinColumn(name = &quot;tag_id&quot;),
              inverseJoinColumns = @JoinColumn(name = &quot;gift_certificate_id&quot;)
      )
      private List&lt;Tag&gt; tags;
      
  getters and setters and other code...
  </code></pre>
  <p>.....</p>
  <pre><code>@Entity
  @Table(name = &quot;tag&quot;)
  public class Tag {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
      private String name;
  
  getters and setters and other code...
  </code></pre>
  <p>I tried to do it like this, but I get exception <code>IllegalStateException: Illegal attempt to dereference path source [null.tags] of basic type</code></p>
  <pre><code>CriteriaBuilder cb = entityManager.getCriteriaBuilder();
  CriteriaQuery&lt;Certificate&gt; query = cb.createQuery(Certificate.class);
  Root&lt;Certificate&gt; certificates = query.from(Certificate.class);
  certificates.fetch(&quot;tags&quot;, JoinType.LEFT);
  query.select(certificates).distinct(true);
  
  query.where(cb.like(certificates.get(&quot;tags&quot;).get(&quot;name&quot;), params.getTag()));
  
  return entityManager.createQuery(query).getResultList();
  </code></pre>