title: Hibernate criteria JOIN + additional condition (with clause) don't work with many-to-many association
body: <p>I'm trying to add additional condition to Join clause using hibernate criteria. In fact, there are some methods, that allow this to do:</p>
  
  <pre><code>createCriteria(String associationPath, String alias, int joinType, Criterion withClause)
  </code></pre>
  
  <p>and </p>
  
  <pre><code>createAlias(String associationPath, String alias, int joinType, Criterion withClause) 
  </code></pre>
  
  <p>They work properly with one-to-one and one-to-many relations. But when I'm trying to use them with entities having many-to-many relations, I'm getting following error:</p>
  
  <pre><code>Caused by: org.postgresql.util.PSQLException: No value specified for parameter 1.
  </code></pre>
  
  <p>Can anybody help me?
  The rude example is below:</p>
  
  <pre><code>@Entity
  public class Person {
  
  @Id
  @GeneratedValue
  private Long id;
  
  @ManyToMany
  private Set&lt;PersonName&gt; names;
  
  }
  
  public class PersonName {
  
  @Id
  @GeneratedValue
  private Long id;
  
  @Column
  private String name;
  
  }
  public class PersonDao extends HibernateDaoSupport {
  
  public List&lt;Person&gt; findByName() {
      Criteria criteria = getSession().createCriteria(Person.class, "p");
      criteria.createCriteria("p.names", "names", JoinType.INNER_JOIN, Restrictions.eq("name", "John"));
      return criteria.list();
  }
  }
  </code></pre>
  
  <p>the Query being generated is </p>
  
  <pre><code>select this_.id as y0_ from person this_ 
      inner join debtor_info this_1_ on this_.id=this_1_.id 
      left outer join person_person_name personname3_ on this_.id=personname3_.person_id and ( name1_.name=? ) 
      left outer join person_name name1_ on personname3_.person_name_id=name1_.id and ( name1_.name=? )
  </code></pre>
  
  <p>As you can see, join condition is being added two times, what is obviously  incorrect</p>
  
  <p>Thanks in advance.</p>
  
  <p>BTW I'm using postgresql 9, Hibernate 3.6.3 </p>