title: Using JPA Criteria Builder with table joins
body: <p>I'm trying to use the JPA Criteria Builder to join two tables, <code>Country</code> and <code>Geotarget</code>.
  The equivalent <code>SQL</code> is</p>
  
  <pre><code>Select distinct Country.* from Country Inner Join Geotarget
   where Geotarget.Country_ID = Country.ID;
  </code></pre>
  
  <p>my code is </p>
  
  <pre><code>     CriteriaBuilder criteriaBuilder getTransactionalEntityManager().getCriteriaBuilder();
      CriteriaQuery&lt;Country&gt; criteriaQuery = criteriaBuilder.createQuery(Country.class);
      Root&lt;Country&gt; root = criteriaQuery.from(Country.class);
      Join&lt;Geotarget, Country&gt; geotargetJoin = root.join(Geotarget_.country, JoinType.INNER);
      Predicate predicate = criteriaBuilder.equal(Country_.id,Geotarget_.country);
      criteriaQuery = criteriaQuery.where(predicate);
      criteriaQuery.select(Country.class).distinct(true);
      return findAllObjects(criteriaQuery);
  </code></pre>
  
  <p>But is wrong, it doesn't even parse in places. In particular i can't seem to find the code for either the join line, or the equals cause which doesn't seem to like to compare two fields.
  Can you help me, with the correct code.</p>