There are two classes A and B. Class A has a collection of objects of class B in it. Class B has a field X. I'd like to be able to return list of objects of class A that have in their collections objects of type B having some specific value of their property X. Is it even possible?
So far I have tried something like:
Root<A> root = criteriaQuery.from(A.class);
criteriaQuery.select(root);
criteriaQuery.where(root.get("bCollection").get("x").in("value"))
but of course it does not work. How to handle this? Class B is mapped as a nested-component like this:
<set name="bCollection" table="bCollection">
<key column="a_id" />
<composite-element
class="example.B">
<many-to-one name="x" column="b_id" not-null="false"
cascade="none" foreign-key="b_fk" />
</composite-element>
</set>
I hope someone knows... thank you!