-->
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: subquery with modified projection
PostPosted: Thu Jan 24, 2008 11:25 am 
Newbie

Joined: Thu Jun 14, 2007 5:38 am
Posts: 6
Hi!

I have a subquery:

DetachedCriteria subquery =
DetachedCriteria.forClass(SemopsTransaction.class, "T");
subquery
.add(Restrictions.eq("paymentStatus",status)
.......

Criteria criteriaCount = subquery.getExecutableCriteria(sessionFactory.getCurrentSession());

criteriaCount.setProjection(Projections.countDistinct("idTransaction"));

int count = (Integer)criteriaCount.uniqueResult();

Affter count is queried I want to use the same subquery (with some modification) to get entries from the table (without any projection):

Criteria criteria = subquery.getExecutableCriteria(sessionFactory.getCurrentSession());

criteria .add(Property.forName("E.timestamp").in(subqueryGroup))
.setFetchMode("E", FetchMode.JOIN);

List<SemopsTransaction> list = criteria.list();

At the first time I want to get back only the count (it works) and with the second query (that use the same subquery) I need all columns from the table.

The problem is that if I set the count at the first query it will take part in the second query as well... I know If I add new projection to the second query I can avoid the count but I need all entries from the table and I don't want to specify each column separately for projection...

So How can I do with subquery + criteria:

first: select count(T) from <subquery>
second: select * from <subquery>


Thx,
topicfun


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.