title: CriteriaBuilder.and & CriteriaBuilder.or, how-to?
body: <p>I'm trying to change the following HQL to use JPA Criteria:</p>
  
  <pre><code>select distinct d from Department d 
  left join fetch d.children c 
  where d.parent is null 
  and (
      d.name like :term 
      or c.name like :term
      ) 
  order by d.name
  </code></pre>
  
  <p><code>Department</code> has a <code>Set&lt;Department&gt;</code> of children.</p>
  
  <p>Criteria:</p>
  
  <pre><code>CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
  CriteriaQuery&lt;Department&gt; c = cb.createQuery(Department.class);
  Root&lt;Department&gt; root = c.from(Department.class);
  root.fetch("children", JoinType.LEFT);
  Path&lt;Department&gt; children = root.join("children", JoinType.LEFT);
  c.orderBy(cb.asc(root.get("name")));
  c.distinct(true);
  c.where(cb.isNull(root.get("parent")));
  String param = "%" + "term" + "%";
  cb.and(cb.like(root.&lt;String&gt; get("name"), param));
  cb.or(cb.like(children.&lt;String&gt; get("name"), param));
  
  TypedQuery&lt;Department&gt; tq = getEntityManager().createQuery(c);
  departments = tq.getResultList();
  </code></pre>
  
  <p>I know it can be a bit terse, however, the HQL returns 24 and Criteria version 28. I think I'm not handling:</p>
  
  <pre><code>and (x = y OR z = y)
  </code></pre>
  
  <p>correctly. Any pointers will be greatly appreciated.
  Thanks.</p>