No, but I couldn't find the answer in the documentation.
I made a test in the meantime, and it is actually working.
Unless you try to
join fetch two collections in the same query (but the documentation says it is not working for the moment ;-)
I'm actually trying to preload my caches with a backgroung thread. Loading all entites is not a problem:
Code:
Session.find("from <entity>");
But when it comes to preload the relationships/collections, the only way I found was:
Code:
Session.find("from <entity> e fetch join e.<role1>");
Works fine until the <entity> has more than one collection. In this situation, a single HSQL query loading the entity and fetching all its relations at once is not possible. I end-up doing the following:
Code:
Session.find("from <entity> e fetch join e.<role1>");
Session.find("from <entity> e fetch join e.<role2>");
Although it loads the entities twice, it is actually faster than iterating through the entities and initializing the <role2> collection for each (using <role2>.size() or Hibernate.initialize(<role2>).
Is there any other better way to preload these collections?
The bottom line is I'd like to preload an entire graph of objects into memory...