Hi all,
I'm suppose this is a simple question, but I couldn't find anything on the Net (maybe I was looking with the wrong search terms)...
What I want to do is create an HQL query that retuns the count of a class that has another class appearing in the Set of one if it's properties. Let me try with an example :)
Let's say I have a class "recipe" and a class "ingredient". ingredient is a normalized entity. So, recipe has a property ingredients that is a set of ingredient items.
Code:
<class name="Recipe" table="recipe">
...
<set name="ingredients" table="recipe_ingredient" cascade="none">
<key column="recipe_id" />
<many-to-many column="ingredient_id" class="Ingredient" />
</set>
...
</class>
Code:
<class name="Ingredient" table="ingredient">
...
</class>
I'd like to count the recipe items that contain a specific ingredient (passed in with ingredient id), something like:
Code:
select count(x) from Recipe as x where x.ingredients contains (select y from Ingredient where y.id = ?)
Any help appreciated!
Best regards,
James