title: Complex Hibernate Projections
body: <p>I want to ask, it is possible that I create query projections and criterion for more than one level deep?
  I have 2 model classes:</p>
  
  <pre><code>@Entity  
  @Table(name = "person")  
  public class Person implements Serializable {
      @Id
      @GeneratedValue
      private int personID;
      private double valueDouble;
      private int valueInt;
      private String name;
      @OneToOne(cascade = {CascadeType.ALL}, orphanRemoval = true)
      @JoinColumn(name="wifeId")
      private Wife wife;
         /*   
          *  Setter Getter    
          */
  }
  
  
  @Entity 
  @Table(name = "wife")  
  public class Wife implements Serializable {
  
      @Id
      @GeneratedValue     
      @Column(name="wifeId")
      private int id;
      @Column(name="name")
      private String name;
      @Column(name="age")
      private int age;            
      /*
       *  Setter Getter
       */       
  }
  </code></pre>
  
  <p><strong>My Criteria API :</strong> </p>
  
  <pre><code>ProjectionList projections = Projections.projectionList(); 
  projections.add(Projections.property("this.personID"), "personID");
  projections.add(Projections.property("this.wife"), "wife");
  projections.add(Projections.property("this.wife.name"), "wife.name");
  
  Criteria criteria = null; 
  criteria = getHandlerSession().createCriteria(Person.class); 
  criteria.createCriteria("wife", "wife", JoinType.LEFT.ordinal()); 
  criterion = Restrictions.eq("wife.age", 19);  
  criteria.add(criterion); 
  criteria.setProjection(projections);
  criteria.setResultTransformer(Transformers.aliasToBean(Person.class)); 
  return criteria.list();
  </code></pre>
  
  <p>and I hope, I can query Person, with specified criteria for wife property, and specified return resultSet.
  so i used Projections for getting specified return resultSet</p>
  
  <p>I want personID, name(Person), name(Wife) will returned. how API i must Use, i more prefer use Hibernate Criteria API.</p>
  
  <p>This time, I used code above for getting my expected result, but it will throw Exception with error message : 
  <code>Exception in thread "main" org.hibernate.QueryException: could not resolve property: wife.name of: maladzan.model.Person</code>,
  and whether my <code>Restrictions.eq("wife.age", 19);</code> is correct for getting person which has wife with 19 as her age value ?</p>
  
  <p>Thanks</p>