-->
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: Criteria with setMaxResults returning wrong count
PostPosted: Wed Feb 20, 2008 9:17 am 
Newbie

Joined: Wed Feb 20, 2008 8:53 am
Posts: 3
Hello,

My question may be related to HHH-2931, but I'm not sure. Wondering if anyone else has experienced this problem.

I am using a Criteria and joining tables with a setResultTransformer(CriteriaSpecification.Distinct_Root_Entity) to return a List of qualifying rows. I am specifiying a setFirstResult and a setMaxResults value on this Criteria.

When the setMaxResults value is set to a number that is less than the actual number of qualifying rows in my database, I receive the wrong count. If I change the setMaxResults value to be greater than the number of qualifying rows in my database, I receive the correct count.

I believe that I am successfully using the Criteria with setMaxResults somewhere else in my code. The difference is that the tables joined in that instance have a 1:1 relationship. The tables that I am using that produce the wrong count have a potential for a 1:many relationship.

Just wondering if anyone has experienced this problem, or if this is a similar issue to HHH-2931?

Thanks in advance for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 3:23 pm 
Newbie

Joined: Wed Feb 20, 2008 8:53 am
Posts: 3
Hello all,

I have been doing some additional testing today, and it really appears that a Criteria does not work if joining tables with a potential 1:many relationship. When I remove the joins from my Criteria, my results are fine.

Has anyone else seen this happen? Does Criteria allow joins on tables of 1:many? I have not been able to find anything specific in the documentation.

Thanks again.


Top
 Profile  
 
 Post subject: Criteria with setMaxResults
PostPosted: Mon Feb 25, 2008 3:44 am 
Newbie

Joined: Thu Dec 01, 2005 8:43 am
Posts: 3
If u look at the SQL created by the Criteria with setMaxResults, you will notice that the number of objects is actually applied at the database level. Thus, if u have 10 records each with say 5 items joined and u do a Criteria query on the joined result set (no MaxResults) You will get 50 rows. Setting Max Results to 20, will return 20 rows from the DB - ie first 10 records and their children


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.