What is the best way to define a hibernate filter on class A to filter by some condition on class B where A-> B is many-to-one?
The only method I know is using a subselect (as below). But I don't like this method because it requires SQL. The idea of using SQL like this seems pretty flaky. How can I guarantee Hibernate won't break my SQL by messing with table aliases etc? Also, it gets messy if I have to traverse many relationships this way e.g. if I have A->B->C and I want to filter A on a property of C.
Is there a better way?
Code:
<class name="A>
    ....
    <many-to-one name="b" class="B"/>
    <filter name="bName" condition=":bName = (select name from b where a.b=b.id)"/>
</class>
<class name="B>
    ....
    <property name="name"/>
</class>
Thanks in advance,
David