I've inherited a database model that I'm slowly mapping with Hibernate. I've come across a many-to-many relationship I'm having a lot of difficulty mapping.
Table FOO:
foo_id (pkey)
other_id (int)
...
Table BAR:
bar_id
...
Table FOO_BAR
other_id
bar_id
The issue is that the many-to-many mapping table uses a different column - one that is guaranteed unique but NOT the primary key of the table - when creation the relationship between the two records.
The problem is that Hibernate using this type of property:
Code:
<bag name="bars" table="FOO_BAR">
<key column="other_id" />
<many-to-many class="xyz.Bar" column="bar_id" />
</bag>
The Hibernate SQL generated will always use the primary key of the FOO table rather than the FOO.other_id which is what I need. I've tried various approaches to this and I'm unable to get this to work (short of creating a VIEW on top of the FOO_BAR table that resolves other_id to the foo_id).
This can be read-only, I just want to be able to model this correctly. I should be able to specify the join-column somewhere, but it doesn't seem clear to me where I can...