title: Map hibernate projections result to java POJO model
body: <p>I've been using spring and hibernate for this past few weeks and I've always been learning something new there.</p>
  
  <p>Right now I've got a problem that I want to solve with Projections in Hibernate.</p>
  
  <p>Suppose there is a model <code>Person</code> and that model has many <code>Car</code>. The following are how the class definitions roughly gonna look like:</p>
  
  <pre><code>public class Person implements java.io.Serializable {
      private Integer id;
      private String name;
      private List&lt;Car&gt; cars;
      private Integer minYear; // Transient
      private Integer maxYear; // Transient
  }
  
  public class Car implements java.io.Serializable {
      private Integer id;
      private Integer year;
  }
  </code></pre>
  
  <p>The problem here is I want to get the <code>minYear</code> (<code>maxYear</code>) of each <code>Person</code> to be filled by the earliest year (latest year) of the <code>cars</code> they have.</p>
  
  <p>Later I found a solution to use <code>Projections</code> but I stumbled upon <code>org.hibernate.QueryException: could not resolve property: minYear of: model.Person</code> and here is the code of the db operation:</p>
  
  <pre><code>Criteria criteria = sessionFactory.getCurrentSession().createCriteria("model.Person");
              criteria.add(create(personInstance));
              criteria.createAlias("minYear", "minYear");
              criteria.setProjection(Projections.min("cars.year").as("minYear"));
  </code></pre>
  
  <p>Is there anyway to store the aggregation value in transient method using <code>Projections</code> because I just want to avoid using plain SQL and HQL as much as possible.</p>