Hibernate version: 3.2
Database: Oracle 10g
Hi all,
The standard one-to-many mapping assumes two classes, Foo and Bar which are related to each other as follows:
Code:
Set Foo.getBars() // of Bar instances
The mapping would be
Code:
<class name="Foo" table="foo">
...
<set role="bars" table="bar">
<key column="foo_id"/>
<one-to-many class="Bar" not-found="ignore|exception"/>
</set>
</class>
I use the <set> collection for the purpose of this example, it could be a different one.
Bar's table requires an extra column, which holds the FK to Foo. This allows Foo to be assigned a collection of Bars based on the value of the foo_id column in Bar.
THE PROBLEM arises when I want multiple classes to have one-to-many mappings to Bar. Let's say I want Foo1, Foo2, Foo3... etc. to all have a one-to-many mapping to Baz. So I would have the following relations:
Code:
Set Foo1.getBars()
Set Foo2.getBars()
...
Now the FK column in Baz needs an additional FK_TYPE column to determine which FooX class it references.
I couldn't find discussions of this situation (or how to map it) in literature, documentation, or int he forums.
Is this possible?
How would I structure my mappings to do this?
Thanks!