I wonder if it's possible to define Set
in Hibernate mapping in a such way, that element would specify not column in original (FOO) table, but in joined one (BAR). Let's say we have some FooContainer.hbm.xml
, which contains Set
of Foo
objects:
<set ...>
<key column="COLUMN_FROM_BAR" />
<one-to-many class="xyz.Foo" />
</set>
Here FOO has FK to BAR (FOO.BAR_ID), so joining is done through element in Foo.hbm.xml:
<many-to-one class="xyz.Bar" fetch="join" column="BAR_ID" foreign-key="barId" ... />
which results in joined FOO-BAR select whenever xyz.Foo
is fetched.
Problem is that where condition of generated Set
fetching select is something like:
... WHERE _FOO_0.COLUMN_FROM_BAR = ?
when desired one is:
... WHERE _BAR_0.COLUMN_FROM_BAR = ?