title: Hibernate Criteria API and Scalar Subqueries
body: <p>I want to translate a HQL query to Criteria API but I don't know if it's possible to write the same thing with Criteria.</p>
  
  <p>The HQL looks like this:</p>
  
  <pre><code>select distinct new DataTransferObject(property1, property2, ..., (select NVL(property3, null) from Table1 where property3 in elements(...) and ... ), property4, ..., (select .....), ...)
  from Table2 as table2
  left join table2.property5 as property5
  (... more left joins ...)
  where
  .....
  </code></pre>
  
  <p>I started to write my Criteria like this:</p>
  
  <pre><code>getSession().createCriteria(Table2.class, "table2")
  .createAlias("table2.property5", "property5")
  (...more createAlias...)
  .add(Expression/Restriction
  ....
  </code></pre>
  
  <p>I then created a ProjectionList with all the constructor arguments except those (select ...).</p>
  
  <p>and at the end:</p>
  
  <pre><code>criteria.setProjection( projectionList).setResultTransformer( Transformers.aliasToBean(DataTransferObject.class) ) .list()
  </code></pre>
  
  <p>My question is how to add those (select ...) to the projectionList ????</p>
  
  <p>What I try to achieve is to make a subquery in the select clause (scalar subqueries), not in the where clause, but using Criteria API</p>