title: Select last record in group using hibernate criteria
body: <p>I want to get this SQL using criterias</p>
  
  <pre><code>select A.evaluated_employee_id, A.created_date, A.total_grade
  from employee_performance_assessment A
  join
  (  select evaluated_employee_id, max(created_date) as maxdate, status, total_grade
      from employee_performance_assessment
      group by evaluated_employee_id
  ) B on A.evaluated_employee_id = B.evaluated_employee_id and A.created_date = B.maxDate
  </code></pre>
  
  <p>I am doing the following</p>
  
  <pre><code>    DetachedCriteria dc = DetachedCriteria.forClass(EmployeePerformanceAssessmentBO.class);
      dc.createAlias("evaluatedEmployee", "e");
      dc.setProjection(Projections.projectionList().add(Projections.max("createdDate"))
  .add(Projections.groupProperty("evaluatedEmployee")));
   dc.addOrder(Order.asc("e.lastName")).addOrder(Order.asc("createdDate"));                   
      dc.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
      return getDAOHibernateTemplate().findByCriteria(dc);
  </code></pre>
  
  <p>But this generates the subquery inside the WHERE clause
  Any idea how to join two criterias from the same table (class)?</p>