Hi,
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.
The HQL looks like this: 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 .....
I started to write my Criteria like this:
getSession().createCriteria(Table2.class, "table2") .createAlias("table2.property5", "property5") (...more createAlias...) .add(Expression/Restriction ....
I then created a ProjectionList with all the contructor arguments except those (select ...).
and at the end:
criteria.setProjection( projectionList).setResultTransformer( Transformers.aliasToBean(DataTransferObject.class) ) .list()
My question is how to add those (select ...) to the projectionList ????
Edit: What I try to achieve is to make a subquerie in the select clause, not in the where clause, but using Criteria API
|