title: Hibernate query/criteria returning duplicate data
body: <pre><code>criteria = createCriteria("employee");
  criteria.add(Restrictions.eq("name", "Jack"));
  criteria.createAlias("certificate", "cert");
  criteria.add(Restrictions.eq("cert.certType", "MSFT"));  
  
  criteriaList = criteria.list();
  </code></pre>
  
  <p>Given the data below, I think the query above should have returned one record that contains a set(set size=2) of certificates but I get the same record duplicated twice(once for each record in Certificate table). Why is this happening? </p>
  
  <p><strong>Employee Table:</strong>         </p>
  
  <pre><code>EMP_ID          NAME    
  123             Jack                                
  111             Mary            
  000             Larry   
  </code></pre>
  
  <p><strong>Certificate table data</strong></p>
  
  <pre><code>emp_id      certificate_type    seq_no
  123         MSFT                  1
  123         MSFT                  2
  111         English               1
  </code></pre>
  
  <p><strong>employee.hbm.xml</strong></p>
  
  <pre><code>&lt;class name="com.Employee" table="Employee" entity-name="employee" mutable="false"&gt;
          &lt;cache usage="read-only"/&gt;
          &lt;id name="id" column="employee_id"/&gt;
          &lt;set name="certificate" fetch="select" inverse="true" lazy="false" &gt;
              &lt;key column="employee_id" /&gt;
              &lt;one-to-many class="com.Certificate" entity-name="CertificateType"/&gt;
          &lt;/set&gt;
  &lt;/class&gt;    
  </code></pre>
  
  <p><strong>certificate.hbm.xml</strong></p>
  
  <pre><code>&lt;class name="com.Certificate" table="Certificate" entity-name="CertificateType" mutable="false"&gt;
      &lt;cache usage="read-only"/&gt;
      &lt;composite-id class="com.usps.nom.tops.model.impl.DispatchLegPKImpl" mapped="true"&gt;
              &lt;key-property name="empId" column="emp_id" /&gt;
              &lt;key-property name="seqNo" column="SEQ_NO" /&gt;
      &lt;/composite-id&gt;
      &lt;property name="certType" column="certificate_type"/&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p><strong>POJOs</strong></p>
  
  <pre><code>public class Employee {
     private int id;
     private String ame;  
      //getters and setters
      public boolean equals(Object obj){}
  }
  public class Certificate {
     private int emp_id;
     private String certType; 
     private String seqNo;
     //getters and setters   
     public boolean equals(Object obj){}
      }
  </code></pre>
  
  <p><strong>EDIT:</strong>
  If I put the result (ie criteriaList in my example) in a set, then it gets rid of the duplicate record. </p>
  
  <pre><code>Set&lt;Employee&gt; empSet = new HashSet&lt;Employee&gt;(criteriaList); 
  </code></pre>