title: JPA 2 criteria query with hibernate fails to left join
body: <p>In my application I have Roles which have Permissions, I used to do this:</p>
  
  <pre><code>   Query query =
          em.createQuery(
              "SELECT distinct r FROM Role r left join fetch r.permissions "
              + "where r.domain = ? " + "order by r.createdOn ").setParameter(
              1, domain);
  
      return query.getResultList();
  </code></pre>
  
  <p>But wanted finer control over lazy initializations. So I am trying this but it is not working because the join is executing as if it was an inner join, not bringing one role and its permissions but one result per row and per permission too.</p>
  
  <pre><code>public List&lt;Role&gt; findAll()
  {
      CriteriaBuilder criteriaBuilder;
      CriteriaQuery&lt;Role&gt; criteriaQuery;
      Root&lt;Role&gt; queryRoot;
      Order createdOnDesc;
      TypedQuery&lt;Role&gt; typedQuery;
      List&lt;Role&gt; roleResultList;
  
      //initialize query system
      criteriaBuilder = em.getCriteriaBuilder();
  
      //select * from Role
      criteriaQuery = criteriaBuilder.createQuery(Role.class);
      queryRoot = criteriaQuery.from(Role.class);
  
      //join permissions by default "LEFT"
      //***THIS LINE IS FAILING*** ????
      queryRoot.join(Role_.permissions);
  
      //get query
      typedQuery = em.createQuery(criteriaQuery);
  
      //the steps below must be done to avoid lazy initialization exceptions
      //in case we want to access the list at a later time
      roleResultList = typedQuery.getResultList();
  
      for (Role role : roleResultList)
      {
          role.getPermissionsList();
      }
  
      return roleResultList;
  }
  </code></pre>
  
  <p>Any thoughts or ideas will be highly appreciated.</p>