title: Hibernate-Criteria: Use multiple conditions in 'ON Clause'
body: <p>I have a situation that I need to apply another Condition inside ON clause while using Hibernate Criteria.</p>
  
  <p>I am writing my MySQL and I am unable to find any reasonable way of converting it in Hibernate Criteria.</p>
  
  <pre><code>SELECT s.StudentID AS StudentID, sc.CourseID AS CourseID
  FROM Student s 
       LEFT JOIN StudentCourse sc ON 
            (sc.StudentID = s.StudentID AND sc.CourseID = 'XXX')
  </code></pre>
  
  <p><strong>What I am doing in this Query</strong></p>
  
  <p>I want all the student List either enrolled in specified course or not.</p>
  
  <p>IF I have four Students the and only one student is enrolled in a course the result should be like</p>
  
  <pre><code>StudentID, CourseID
  1          NULL
  2          XXX
  3          NULL
  4          NULL
  </code></pre>
  
  <p><strong>So far I what I have done</strong> is</p>
  
  <pre><code>Criteria cr = getSession().createCriteria(Student.class);
  cr.createAlias("studentCourse", "sc", CriteriaSpecification.LEFT_JOIN)
      .add(Restrictions.eq("sc.CourseID", 'XXX'));
  </code></pre>
  
  <p>By running this statement I get the query equivalent to the following query</p>
  
  <pre><code>SELECT *
  FROM Student s
       LEFT JOIN StudentCourse sc ON (sc.StudentID = s.StudentID)
  WHERE sc.CourseID = 'XXX'
  </code></pre>
  
  <p>Now this query does not serve the purpose of the query. It returns only one row where CourseID is not null.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Hibernate Version 3.4.0GA</p>