Hello,
I have this relationship mapped up:
Item <--> Store (Many-to-Many)
Item <-- Brand (Many-to-one, An item can only belong to one brand)
... (and serveral other unrelated mappings to Item)
To create a search, I used this critiera to find all items that belonged to a brand:
Code:
crit.add( Restrictions.eq( "item.brand", brand.getId() ) );
However I am having more problems creating a criteria for getting all items that belong to a specific Store (Because of the many-to-many relationship). I could easily do it in HQL:
"... where store in elements( item.stores )"
However i want it to fit in nicely with the Restrictions API because I still want to get all items that belong to a specific brand AND a specific Store.
I was looking at Expression.in( store, item.getStores() ), but as the first argument is a String, something tells me that its not what im looking for.
Any ideas?
Im using Hibernate v3.2.3.ga with Hibernate Annotations (no JPA), MySQL 5.0 and JDK 5.
Regards,
John
Code: