-->
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.  [ 3 posts ] 
Author Message
 Post subject: Need for experience... HQL query "join fetch" vs M
PostPosted: Thu Dec 16, 2004 12:10 pm 
Beginner
Beginner

Joined: Thu Dec 16, 2004 11:54 am
Posts: 26
Location: Brussels, Belgium
Hibernate version: 2.1.7

Hi,
My question might get me down in flames, I know I'm new to Hibernate, and hence would like to hear about more experienced users about fetch strategies...

I have the following (among others) schema:

"Catalog" * <-> * "Product" -> * "Option"

When the user displays a catalog page, I only show available products, depending on the stockAvailable field ( > 0 ) in the Option.
Now my question is what should I best do to get the available products.
I tried different solutions from loading Products lazily, then filtering them in memory.
Now it behaves ok, but overtime Products will not be supplied anymore and I might end loading quite a lot of Product (and Option) object for nothing.
So I thought I should (like I would do in SQL) filter the Products on those having available Options at DB level.
Now is it possible to (I didn't manage though, read about fetch join, not needing aliases cause they shouldn't appear in WHERE clause) to do an HQL query a la :
Code:
from Catalog c
join fetch c.products p
join fetch p.options o
where c.id = :id
and o.stockAvailable > 0

or rather fetch products for that catalog, put them in the Catalog 's association myself... or?
Stupid question in that, that I would like to obtain best performances, now and later (I believe I will not always be on the project (or anyone else) to fine tune this overtime...)?
So any advice, or even only hints would be welcome.
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 16, 2004 1:11 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you cannot fetch more than one collection.
in your case, you need batch-size, check dtd, docs (especially hibernate in action) and test

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 16, 2004 3:37 pm 
Beginner
Beginner

Joined: Thu Dec 16, 2004 11:54 am
Posts: 26
Location: Brussels, Belgium
First off, thanks for the reply.
This is as far as I got in the docs (especially Hibernate in Action, but that I had to buy on manning.com, since I just can't fond it any where here).
Just got wrong (while it makes perfect sense) that a single collection applied to a query and not to a class!
That's already clearer in my mind now...
Still I'm not happy with the design and stil consider either of those "solutions":
- Shouldn't I put a let's say boolean on Product that would or not confirm it's availability, hence querying the Catalog directly with the "easiest and lightest" query (while other Maps have then to be initialized on that Product class for i18n labels and such)
- or, get the Catalog by id, then query for products being included (many-to-many relationship) in that catalog's id and having Option.stockAvailable > 0
I know this is getting pretty much in details for such a "stupid" newbie problem, but I'd really like to make the best out of Hibernate.
And on another point of view shouldn't Hibernate3's (beta due any time soon, said Gavin this week at JavaPolis) filter make my life easier on that?
There is another question that pops to mind, is this (already or in Hibernate3) possible to have 2 fields pointing (one "read-only") to the same column in database but one filtered? A la:
getProducts();
getAvailableProducts();
like I would do it in Java, just having the filtering being done by the database? (while again not quite sure that makes sense)...
Again thanks, and I'll keep on printing my bought PDF ;)
Alex


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