title: JPA specification join many tables
body: <p>I have Shelf Entity, HubProducts Entity, Products Entity.</p>
  <ol>
  <li>Shelf has HubProducts</li>
  <li>HubProducts has Product</li>
  <li>Product has name</li>
  </ol>
  <pre class="lang-java prettyprint-override"><code>public class Shelf extends BaseEntity {
      
      @ManyToMany(cascade = CascadeType.ALL)
      @JoinColumn(name = &quot;hub_product_id&quot;)
      private Set&lt;HubProducts&gt; hubProducts;
  }
  
  public class HubProducts extends BaseEntity {
      
      @JsonBackReference
      @JoinColumn(name = &quot;products_id&quot;)
      @ManyToOne(fetch = FetchType.LAZY)
      private Products product;
  }
  </code></pre>
  <p>Similarly, Product entity has name field.</p>
  <p>Now I want to query using JPA specification such that all records matching with product name should be filtered</p>
  <p>For that purpose, I have written:</p>
  <pre class="lang-java prettyprint-override"><code>private static void applyKeywordFilter(CriteriaBuilder cb,
                                         Root&lt;Shelf&gt; root,
                                         Collection&lt;Predicate&gt; predicates,
                                         String keyword) {
      if (!ObjectUtils.isEmpty(keyword)) {
          predicates.add(cb.or(
              // Shelf-&gt;hubProducts-&gt;Products -&gt; [name]
              cb.like(root.join(&quot;hubProducts&quot;, JoinType.LEFT).join(&quot;product&quot;,  JoinType.LEFT).get(&quot;name&quot;), &quot;%&quot; + keyword + &quot;%&quot;),
              cb.like(root.get(&quot;shelfDetails&quot;), &quot;%&quot; + keyword + &quot;%&quot;)));
      }
  }
  </code></pre>
  <p>But Unfortunately <code>  cb.like(root.join(&quot;hubProducts&quot;, JoinType.LEFT).join(&quot;product&quot;,  JoinType.LEFT).get(&quot;name&quot;), &quot;%&quot; + keyword + &quot;%&quot;),</code> does not work.</p>
  <p>Can somebody help please?</p>