title: Hibernate and criteria that return the same items multiple times
body: <p>I've "Student" and "Class" in relation many to many. In between there is a linking table.</p>
  
  <p>If I want to retrieve all the students with HQL in the following way, everything is fine:</p>
  
  <pre><code>Query queryObject = getSession().createQuery("from Student");
  return queryObject.list();          
  </code></pre>
  
  <p>With the above code if there are three students I get a list of three students. </p>
  
  <p>If I use criterias, however, it's fine only as long as there are no associations in the linking table.</p>
  
  <pre><code>Criteria crit =  getSession().createCriteria(Student.getClass());        
  return crit.list();
  </code></pre>
  
  <p>With the second code, I get three results only when the linking table is empty. However when I add an association, I get 6 results. Looking at the log, Hibernate generates multiple selects. How is it possible?</p>
  
  <p>Can someone explain why does this happen? How can I fix the criteria in order to return the three records only once?</p>
  
  <p>EDIT</p>
  
  <p>In the Student class I mapped in this way:</p>
  
  <pre><code>@ManyToMany(fetch=FetchType.EAGER)
  @JoinTable(
      name="room_student_rel"
      , joinColumns={
          @JoinColumn(name="id_student")
          }
      , inverseJoinColumns={
          @JoinColumn(name="id_room")
          }
      )
  private List&lt;Room&gt; rooms;
  </code></pre>
  
  <p>In the room (class) I mapped in this way:   </p>
  
  <pre><code>@OneToMany(fetch=FetchType.EAGER,  mappedBy="room")
  @Fetch(FetchMode.SELECT)
  private List&lt;RoomStudent&gt; roomStudents;
  </code></pre>