-->
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: Diference between "select" and "subselect&quo
PostPosted: Wed Jun 07, 2006 2:36 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
Hello Every Body:

After readed the 19.1 Fetching Strategie of Chater 19 of Hibernate Reference Document, I donĀ“t undestand clearly for the diference between "select" and "subselect".

It says:

[quote]
[u]Select fetching[/u] - a second SELECT is used to retrieve the associated entity or collection.
[u]Subselect fetching [/u]- a second SELECT is used to retrieve the associated collections for all entities retrieved in a previous query or fetch.

[/quote]

Can any body talkme about the diference between both?


Top
 Profile  
 
 Post subject: Re: Diference between "select" and "subselect
PostPosted: Wed Jun 07, 2006 5:59 pm 
Beginner
Beginner

Joined: Sat Jun 03, 2006 6:23 pm
Posts: 28
Quote:
Select fetching - a second SELECT is used to retrieve the associated entity or collection.


This one is simply the loading of referenced entities, either one or a collection of them, using the foreign key in the where clause of the statement. E.g. you have a person object and say person.getCats(), and Hibernate does select * from Cat where owner = :person_id.

Quote:
Subselect fetching - a second SELECT is used to retrieve the associated collections for all entities retrieved in a previous query or fetch.


Subselect fetching is a special version of batch fetching: it loads all data in one query instead of multiple batches. This is useful, if, say you got a list of persons, and you were going to call person.getCats() on each of them.

Now, this would result in exactly the same amount of queries, as you have persons, because you execute one select statement like above for each person (this would be the select fetching).

Hibernate can optimize a bit though, and can load all the cats for each of the persons you retrieved previously. Your previous query will be run as a subselect:

select * from Cat c where c.owner in ( select id from Person p where ...)

I think you could create a test program and see what query is actually run. Basically when you call getCats() on your first person object, Hibernate loads the cats not only for what you directly asked, but for all persons you have in your session.

Roland


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.