Hibernate version: 2
Hi, I am a newbie in hibernate and definitely confused.
I have a classic many-to-many relation (e.g. Category and Item). The relational table doesn't have it's own id but uses a combined key consisting of the 2 foreign keys (e.g <CAT_ID, ITEM_ID>). Both collections (Category.items, Item.Categories) are lazy loaded.
I want to retrieve the Item.Categories ids without loading the categories collection.
My first approach was using a query like
Code:
select cat.id from Category cat where :item in elements(cat.items)
My second approach trying to avoid inner selections was
Code:
select cats.id from Item item join item.categories cats where item = :item
Both of them worked fine, but then I was urged to use filtering, so here are my questions :
1) Is there any point trying to use filtering in this case if the collection may not be initialized or referenced (net.sf.hibernate.LazyInitializationException)?
2) If yes how can I do this? What filter should I use (e.g. "select this.id").
3) What is the practical difference with the previous approaches?
Thanks in advance for your time.