Using v. 2.1.4
Trying to build a map for an odd data model that is out of my control. The scenario is as follows.
Child table can be used in multiple Parent tables. Child table has a composite key of two columns. One element of this composite key is referenced in the parent table. Logically this is one parent to many children however this is not enforced in the datamodel so technically this is a many to many relation ship without a junction table.
Below is the mapping in one of the parents:
Code:
<set
name="child"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<many-to-many
class="com.bleh.Child"
column="CHILD_ID"
outer-join="auto"
/>
</set>
The mapping for child is as follows:
Code:
<hibernate-mapping>
<class
name="com.bleh.Child"
table="CHILD"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id
name="primaryKey"
class="com.bleh.ChildPK"
>
<key-property
name="childId"
type="long"
column="CHILD_ID"
/>
<key-property
name="otherChilidId"
type="int"
column="OTHER_CHILD_ID"
/>
</composite-id>
...other properties
</class>
</hibernate-mapping>
When this runs I get the following exception:
Foreign key (child [CHILD_ID])) must have same number of columns as the reference primary key (CHILD [CHILD_ID, OTHER_CHILD_ID]).
I would like to know if this is even possible. There are approximately 20 parent classes and there are about 10 properties on the child so it would be nice to avoid having to write so many composite components as referenced here
http://www.xylax.net/hibernate/composite.html
Thanks for any help or pointers to my obvious newbie oversights.