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