title: Hibernate Many-to-Many Criteria Projection
body: <p>EDIT> i am at a dead end... so i can continue looking for the main reason .. Please tell me how to make a simple criteria for many to many relationships which has more than one eq restrictions, for an example, how to get the person speaking eng &amp; german in the example shown here...</p>
  
  <p>My situation is like this i have two classes person and languages, with a n,m relationship.. And i am using a criteria to do the search - get all the persons which speak ex. English and German</p>
  
  <pre><code>@Entity
  public class Person implements Serializable {
      private int id;
             ...........
      private Set&lt;Languages&gt; languages = new HashSet&lt;Languages&gt;();
         ...............
      @ManyToMany
      @JoinTable(name = "link_person_languages")
      public Set&lt;Languages&gt; getLanguages() {
         return languages;
      }
  }
  
  @Entity
  public class Languages implements Serializable {
      private int id;
      private String name;
      @Id
      @GeneratedValue
      public int getId() {
          return id;
      }
      @Column(nullable = false, length = 40, unique = true)
      public String getName() {
          return name;
      }
  </code></pre>
  
  <p>Criteria</p>
  
  <pre><code>    Criteria crit = session.createCriteria(Person.class);
      crit.setCacheable(true);
      ProjectionList projList = Projections.projectionList();
      projList.add(Projections.property("languages"));
      c = enumMap.get(attr);
      if (c.isChanged()) {
         Criteria crit2 = crit.createCriteria("languages");
         Object[] o = (Object[]) c.getAnswer();
         Conjunction con = Restrictions.conjunction();
         for (int j = 0; j &lt; o.length; j++) {
                Criterion tmp = Restrictions.eq("id", ((Languages)o[j]).getId());
                con.add(tmp);
         }
         crit2.add(con);
  
      }
      crit.setProjection(projList);
      retList = crit.list();
  </code></pre>
  
  <p>And the funny thing is, if i set it only for one language, i get the proper list of persons, but for more than one language i get none, i rechecked my base and set one person specifficaly to speak the 2 languages. But what tips mi more than anything is that the result from the projection in the Object[] on the place where the Set languages should be, there is NULL value......</p>
  
  <p>please help
  tnx</p>