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