-->
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: join fetch and scroll
PostPosted: Fri Jan 11, 2008 2:34 pm 
Newbie

Joined: Fri Jan 11, 2008 1:33 pm
Posts: 1
Location: Lille (France)
Hello,

I have a model where I have a big collection of an object type which has childs. I want hibernate to get a part of my collection and all childs in one select.

So I thought about "join fetch" which avoids n select to get the child of each object in the collection (where n is the size of the collection).

I didn't want to get the whole collection in my select so I think about setMaxResult() and better scroll() because it tells you if there are more objects.

But "join fetch" and scroll() don't work together...

I tried to understand why : If i take a

Code:
Collection<A>


and A has an attribute :
Code:
public class A{
          private Collection<Thing> things;


and the HQL query :

Code:
"from A a left join fetch a.things where a member of ..."


then Hibernate can't sure that every element A of the collection get all its Thing before he reaches the end of the ResultSet of the query.

So if you use a scroll and stop scrolling before the end of the ResultSet, you may have invalid objects.

Am I right ?

It's important for me to understand why "join fetch" and scroll() don't work together because it can help me to solve my problem.

Thanks.

Fabrice

Hibernate version: 3.2.2.ga


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 11:32 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
The scrolling/pagination capabilities rely on ROWNUM-type functions, they work with the size of your resultset. They wrap your original query on a simple outer query that says

Code:
select * from (<original query>) where rownum ...


If you do fetch joins, the size of your resultset contains rows belonging to a number of children per each parent, therefore the number of rows does not reflect the quantity of "parent" entities anymore.

scrolling/pagination is only possible when Hibernate is able to work keyset-style, with one row representing each top-level entity of your query.

_________________
Gonzalo Díaz


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.