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 ...)
w开发者_如何学Chere
.....
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 constructor 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 ????
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
精彩评论