title: Hibernate criteria query for join with condition
body: <p>I have the following SQL query:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT
      tos.ID
  FROM
      TESTCYCLE_OPCO_SETTING tos
          JOIN OPCO o
              ON o.ID = tos.OPCO_ID
          JOIN TESTCYCLE tc
              ON tc.ID = tos.TESTCYCLE_ID
          LEFT OUTER JOIN BUILD b
              ON b.ID = tc.BUILD_ID
          LEFT OUTER JOIN BUILD_OPCO_SETTING bos
              ON bos.BUILD_ID = b.ID
              AND bos.OPCO_ID = o.ID
  </code></pre>
  
  <p>What is needed is that the OPCO_ID form the TESTCYCLE_OPCO_SETTING is used to fetch the corresponding BUILD_OPCO_SETTING. I have done this with the "AND" condition in the last JOIN.</p>
  
  <p>I now want to create a Hibernate Critera query out of this and created the following aliases for the joins:</p>
  
  
  
  <pre><code>criteria.createAlias("opco", "opco");    
  criteria.createAlias("testcycle", "testcycle");
  criteria.createAlias("testcycle.build", "build", CriteriaSpecification.LEFT_JOIN);
  criteria.createAlias("build.buildOpcoSettings", "buildOpcoSetting", CriteriaSpecification.LEFT_JOIN, Restrictions.eqProperty("buildOpcoSetting.opco.id", "opco.id"));
  </code></pre>
  
  <p>However the 4th alias throws an SQL error and I think I'm using this incorrectly for what I want to achieve. If I replace the property "opco.id" with a specific numeric value it works but this doesn't help me of course.
  Any ideas?</p>