title: Join and inheritance jpa
body: <p>I use spring data, jpa with hibernate implementation</p>
  
  <p>I am writing a advanced search</p>
  
  <pre><code>public class Samples  extends BaseEntity{
      ..
      @Id
      @ManyToOne
      @JoinColumns({
          @JoinColumn(name = "sampling_id", referencedColumnName = "id"),
          @JoinColumn(name = "sampling_year", referencedColumnName = "year")})
      private Samplings sampling;
      ...
  }
  
  @Entity
  @IdClass(SamplingsPK.class)
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  public class Samplings extends  extends BaseEntity{
      @OneToOne
      private Products product;
  }
  
  @Entity
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  public abstract class Products  extends BaseEntity{
      ...
      @ManyToOne(fetch = FetchType.LAZY)
      private ProductTypes productType;
  }
  
  @Entity
  @DiscriminatorValue("TraditionalProducts")
  public class TraditionalProducts extends Products {
      ...
  }
  
  @Entity
  @DiscriminatorValue("GranulateProducts")
  public class GranulateProducts extends Products  {
       @ManyToMany(mappedBy="granulateProducts")
      private Set&lt;Suppliers&gt; suppliers = new HashSet&lt;&gt;();
  }
  
  @Entity
  @DiscriminatorValue("GranulateSamplings")
  public class GranulateSamplings extends Samplings{
      OneToOne(optional = true, fetch = FetchType.EAGER)
      @JoinColumn
      private Suppliers supplier;
      ...
  }
  </code></pre>
  
  <p>and this search method</p>
  
  <pre><code> public Page&lt;Samples&gt; advancedSearch(SamplesSearchDto search, Pageable page) {
       Specification&lt;Samples&gt; specification = (Root&lt;Samples&gt; root, CriteriaQuery&lt;?&gt; cq, CriteriaBuilder cb) -&gt; {
  
           Predicate p = cb.conjunction();
  
           if (search.getProductsId() != null) {
               Join&lt;Samples, Samplings&gt; samplings = (Join) root.join("sampling");
               Join&lt;Samples, Products&gt; product = (Join) samplings.join("product");
               p.getExpressions().add(cb.equal(product.get("id"), search.getProductsId()));
           }
  
          if (search.getSuppliersId() != null) {
              Join&lt;Samples, Samplings&gt; samplings = (Join) root.join("sampling");
              Join&lt;Samplings, Suppliers&gt; supp = samplings.join("supplier");
              p.getExpressions().add(cb.equal(supp.get("id"), search.getSuppliersId()));
              //supplier name field is used in GranulateSamplings
  
          }
  
          return p;
  
      };
  
      return this.findAll(specification, page);
  }
  </code></pre>
  
  <p>For my supplier field search, how I suppose to do the join GranulateSamplings who extend product?
  because  this field is available only in GranulateSamplings entity </p>
  
  <p>Edit</p>
  
  <p>I get this error</p>
  
  <blockquote>
    <p>Unable to locate Attribute with the give name [suppliers] on this
    Managedtype com.lcm.mode.Samplings</p>
  </blockquote>
  
  <p>It's like is not able to do alone the bridge between samplings and suppliers</p>
  
  <p>Edit</p>
  
  <pre><code>Join&lt;Samples, Samplings&gt; samplings = (Join) root.join("sampling");
  Join&lt;GranulateSamplings, Suppliers&gt; supp = samplings.join("supplier");
  p.getExpressions().add(cb.equal(supp.get("id"), search.getSuppliersId()));
  </code></pre>
  
  <p>same issue</p>