-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to get row count of existing criteria
PostPosted: Sat Nov 28, 2009 1:30 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
For existing DetachedCriteria, how to get the row count of its query results?

If we use projection like:

DetachedCriteria existCriteria = ...
existCriteria.setProjection(Projections.rowCount());

It will override existing projections(such as group by, if any), and row count will not be correct.

I hope to have a new criteria wrapping over existing one and add rowCount projection to the new one.

DetachedCriteria newCriteria = new DetachedCriteria(existCriteria)
newCriteria.setProjection(Projections.rowCount());

But current Hibernate does not support this.
Is there any workaround?

Thanks!
Dave


Top
 Profile  
 
 Post subject: Re: How to get row count of existing criteria
PostPosted: Sat Nov 28, 2009 11:09 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
if DetachedCriteria has API to get native SQL, then I can

String nativeSql = detachedCriteria.getNativeSQL("mysql");
select count(*) from (nativeSql)


Top
 Profile  
 
 Post subject: Re: How to get row count of existing criteria
PostPosted: Thu Aug 12, 2010 3:17 pm 
Newbie

Joined: Thu Aug 12, 2010 3:07 pm
Posts: 3
Location: Madrid, Spain
Hi javatwo

I just wanna know if that workaround worked or did you find another solutions?

I have the same problem trying to malke a rowcount of existing criteria.

_________________
I made a covenant with God, he doesn't develop software and I don't do miracles


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

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.