DC wrote:
I have a list of POJOs which have some uninitialized collection properties (one-to-many). Is there a way to fetch this collection property for each of the POJOs in a single query, without one query per POJO in a loop?
pojo1.children
pojo2.children
pojo3.children
pojo4.children
...
Actually the problem goes one step further: The direct collection property is actually initialized but the objects in this collection again have set properties which I need to fetch now, without a query for every one of them... I can only think of doing it manually. Collect the ids of the needed objects in a loop, then execute a query with an in clause. But if I do this I have a separate list of the late-fetched objects and have to somehow distribute/associate them with original list of POJOs.
Hibernate version: 3.0.5
Name and version of the database you are using: Oracle 9
If your session is still open, just accessing the property will cause hibernate to initialize it. Assuming that your session will be closed prior to accessing these collections, you have use Hibernate.initialize(pojo.children) to force initialization of the collection prior to closing the session.
You should also look at the batch-size property in the reference docs.