-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL join fetch and caching
PostPosted: Thu Sep 04, 2003 3:53 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
I'm wondering if the elements of a collection loaded using a "fetch join" are put in the cache (JCS) ?

From the reference documentation:
Code:
from eg.Cat as cat
    inner join fetch cat.mate
    left join fetch cat.kittens

Will the cat.kittens elements be stored in the cache ?

Thx


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 10:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, why?


Do you think its not working?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 3:43 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
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...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 4:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I always counsel against doing cartesian products like this. It is unscalable as the size of the collections increases.


If you *must*, you can do:


from Foo
left join foo.bars bar
left join foo.fums fum


and get them all out of the returned array.


P.S. The syntax is actually "join fetch", not "fetch join".


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.