title: Hibernate Join using criteria and restrictions
body: <p>I have 2 entities as</p>
  
  <p><strong>PayoutHeader.java</strong></p>
  
  <pre><code>@Entity
  public class PayoutHeader extends GenericDomain implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;        
      @Column
      private Integer month;
      @Column
      private Integer year;
      @OneToOne
      private Bank bank;
      @Column
      private Double tdsPercentage;
      @Temporal(javax.persistence.TemporalType.DATE)
      private Date **chequeIssuedDate**;
  
      @Temporal(javax.persistence.TemporalType.DATE)
      private Date entryDate;
  
  }
  </code></pre>
  
  <p><strong>PayoutDetails .java</strong></p>
  
  <pre><code>@Entity
  public class PayoutDetails {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;        
  
      @ManyToOne
      private PayoutHeader payoutHeader;
  
      @Column
      private Double amount;
      @Column
      private String bankName;
      @Temporal(javax.persistence.TemporalType.DATE)
      private Date clearingDate;
      @OneToOne    
      private Advisor advisor;
  
      @Column
      private Long **advisorId**;
  }
  </code></pre>
  
  <p>I want to write query using Hibernate Criteria like</p>
  
  <pre><code>Select pd.* from PayoutDetails pd, PayoutHeader ph where pd.payoutheaderId = ph.id and pd.advisorId = 1 and and ph.chequeIssuedDate BETWEEN STR_TO_DATE('01-01-2011', '%d-%m-%Y') AND STR_TO_DATE('31-12-2011', '%d-%m-%Y') ";
  </code></pre>
  
  <p>I have written query like this</p>
  
  <pre><code>public List&lt;PayoutDetails&gt; getPayoutDetails(AdvisorReportForm advisorReportForm) {
          Criteria criteria = getSession().createCriteria(PayoutDetails.class);
  
          if (advisorReportForm.getAdvisorId() != null &amp;&amp; advisorReportForm.getAdvisorId() &gt; 0) {
              criteria.add(Restrictions.eq("advisorId", advisorReportForm.getAdvisorId().toString()));
          }
  
          criteria.setFetchMode("PayoutHeader", FetchMode.JOIN)
                  .add(Restrictions.between("chequeIssuedDate", advisorReportForm.getFromDate(), advisorReportForm.getToDate()));        
  
          return criteria.list();
      }
  </code></pre>
  
  <p>But is giving error as </p>
  
  <blockquote>
    <p>org.hibernate.QueryException: could not resolve property:
    chequeIssuedDate of: org.commission.domain.payout.PayoutDetails</p>
  </blockquote>
  
  <p>I think is is trying to find <code>chequeIssuedDate</code> field in <code>PayoutDetails</code>, but this field is in <code>PayoutHeader</code>. How to specify alias during join ?</p>