title: How to use JPA Criteria API in JOIN
body: <ul>
  <li>I have five tables: Company, Product/Service, Address, Country and
  City.</li>
  <li>A Company can have n products with category, 1 address with 1 country
  and 1 city inside the address entity.</li>
  <li>A user has chosen "England - Leeds".</li>
  <li>I know now that I have to select every companies from db where city
  is Leeds and populate product/service-list with those companies'
  products or services. After that user can select for instance dentist
  from the third list.</li>
  <li>After that I know Enlgand - Leeds - Dentist and I have to populate
  the last list with compenies (dentists in Leeds)</li>
  </ul>
  
  <hr>
  
  <pre><code>public class Company implements java.io.Serializable {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Short companyId;
  @OneToOne(cascade=CascadeType.PERSIST)
  private Address address;
  private String companyName;
  @OneToMany(fetch = FetchType.LAZY, mappedBy = "company",cascade=CascadeType.PERSIST)
  private Set&lt;Product&gt; products = new HashSet&lt;Product&gt;(0);
  </code></pre>
  
  <hr>
  
  <pre><code>public class Product implements java.io.Serializable {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "productId", unique = true, nullable = false)
  private Integer productId;
  private Short branchId;
  private String productName;
  private String sku;
  private String category; ------&gt; I am using this field in company search (dentists, garages etc.)
  </code></pre>
  
  <p>How can I query only those companies which have products with category dentist?</p>
  
  <pre><code>CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
  
  CriteriaQuery&lt;Company&gt; criteria = criteriaBuilder.createQuery( Company.class );
  Root&lt;Company&gt; companyRoot = criteria.from( Company.class );
  //criteria.select(companyRoot);
  
  TypedQuery&lt;Company&gt; q = em.createQuery(criteria);
  List&lt;Company&gt; results = q.getResultList();
  </code></pre>
  
  <p>Now I've got every company, how can I select only the companies with the correct category? I think I will need <code>JOIN</code> but how I don't know how to use it.</p>