title: Getting the field of a child object from a parent object in criteria query. (Hibernate/Persistence)
body: <p>I have an object (A), that has a field that contains another <code>object</code> (B), and B has a field of <code>long</code> type. I want to be able to access B's long type field in a criteria query.</p>
  
  <p>In the example code, we see how to get the field of an object, but is there a way to get objectA.objectB.field in a similar way as the example code looks like?</p>
  
  <p>I have found this example code:</p>
  
  <pre><code>CriteriaQuery&lt;Integer&gt; criteria = builder.createQuery( Integer.class );
  Root&lt;Person&gt; personRoot = criteria.from( Person.class );
  criteria.selec(1)t( builder.max( personRoot.get( Person_.age ) ) );
  criteria.where( builder.equal( personRoot.get( Person_.eyeColor ), "brown" ) );
  Integer maxAge = em.createQuery( criteria ).getSingleResult();
  </code></pre>