title: hibernate createAlias with clause generates wrong query
body: <p>I have the following tables:
  A: id
  B: id, text
  AB: aID, bID</p>
  
  <p>I want to joib A and B where B.text contains the word 'cat'.</p>
  
  <p>This is the hibernate query I do:</p>
  
  <pre><code>Criteria c = session.createCriteria(TableA.class, "A");
  c.createAlias("A.bs", "B", JoinType.INNER_JOIN, Restrictions.like("b.text", "%cat%"));
  c.setProjection(Projections.property("id"));
  </code></pre>
  
  <p>The generated query is:</p>
  
  <pre><code>Select id 
  FROM A a
  INNER JOIN AB ab ON a.id=ab.aID AND (b.text like ?)
  INNER JOIN B b ON b.id=ab.bID AND (b.text like ?)
  </code></pre>
  
  <p>For some reason <code>AND (b.text like ?)</code> appears in both inner joins. I far as I understand its supposed to be only in the second on.
  This causes the following exception:</p>
  
  <pre><code>java.sql.SQLException: No value specified for parameter 2
  </code></pre>
  
  <p>I guess it's happening because it has only one parameters and two '?'.</p>
  
  <p>What am I missing?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Adding the persistent classes:</p>
  
  <pre><code>@Entity
  @Table(name="A")
  Class A {
  
      @Id
      @Column(name="id", length=255)
      protected String id;
  
      @OneToMany
      @JoinTable(name="AB", joinColumns = @JoinColumn( name="aID"), inverseJoinColumns = @JoinColumn( name="bID"))
      @LazyCollection(LazyCollectionOption.FALSE)
      protected List&lt;B&gt; bs;
  
  }
  
  @Entity
  @Table(name="B")
  Class B {
  
      @Id
      @Column(name="id", length=255)
      protected String id;
  
      @Column(name="text", length=255)
      protected String text;
  
  }
  </code></pre>