-->
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.  [ 2 posts ] 
Author Message
 Post subject: Paging on left joined query results
PostPosted: Thu Oct 18, 2007 5:00 pm 
Newbie

Joined: Thu Oct 18, 2007 10:30 am
Posts: 2
Need some help ...

I have two classes - Parent and Child (associated using one-to-many in Parent.hbm.xml and many-to-one in Child.hbm.xml). In the object model, children is an IList of Child in a Parent object.

Need to populate a gridview(asp.net) with results from searching on both the Parent's and Child's attributes:
"select distinct p from Parent as p left join p.children as c where p.Name = :name and c.Age = :age ..." etc;

Now, there are about 100,000 rows in the Parent table, which makes a query.List() from this above HQL slow. I need only 20 records at a time, when the user is paging through search results. However, if the user removes all search criteria, this HQL fetches all 100,000 rows from the table. Is there a easy way to limit this?

Unable to use getFirstResult() and SetMaxResults() because this is a left join, and these functions operate on the join results, and not after applying 'distinct'. (http://www.hibernate.org/117.html#A12)

Hibernate version:1.2
Name and version of the database you are using:Oracle 10g


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 5:17 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I have found this behavior to be unintuitive and, quite frankly, a pain in the arse.

Regardless, the workaround is to use a subquery if your DB supports it:
Code:
SELECT p FROM Parent WHERE p.id IN (SELECT p.id FROM Parent p LEFT JOIN p.Children c WHERE p.Name = :name AND c.Age = :age)


Then you can use SetFirstResut and SetMaxResults as normal.

Hopefully that will solve your problem.

Cheers,

Symon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.