-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Subqueries in the select clause using Criteria API
PostPosted: Fri Feb 12, 2010 6:25 am 
Newbie

Joined: Mon Oct 30, 2006 4:47 am
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.