Hi Hibernate-experts,
since some days I'm fiddling around to find a working mapping, but could not find help google, FAQ, doc, etc., so here's my cry for help:
In effect it's a simple 1:n relationship between two tables from a legacy schema, called PARENT and CHILD in this mail. I need read-only access so that a Parent class contains an ordered Collection of Child instances (List?).
The adversity hereby is the following (the schema belongs to a 3rd party product I can't influence, so don't blame me ;-)
1. The PARENT table has a compound primary key consisting of two attributes (KEY1, KEY2)
2. The two tables are connected via a column "trncode", existing in both tables as a plain vanilla attribute
3. "trncode" isn't unique in the PARENT table (what makes it not really a 1:n relationship, but because I'm only navigating read-only from PARENT, that's not important)
My current mapping looks like this:
Code:
<hibernate-mapping>
<class table="PARENT" name="foo.Parent">
<composite-id>
<key-property name="key1" access="field" column="KEY1"/>
<key-property name="key2" access="field" column="KEY2"/>
</composite-id>
<property name="trnCode" access="field" column="TRNCODE"/>
<property name="parentInfo" access="field" column="PAR_INF"/>
...
<map name="childs" table="CHILD">
<key column="trncode"/>
<map-key type="string" column="trncode"/>
<composite-element class="foo.Child">
<property name="childInfo" access="field" column="CHILD_INF"/>
...
</composite-element>
</map>
</class>
</hibernate-mapping>
Executing this, I get the following error from Hibernate:
Code:
org.hibernate.MappingException: Foreign key (FK9D18367CBF36D4AA:CHILD [trncode])) must have same number of columns as the referenced primary key (PARENT [KEY1,KEY2])
I had similar results when I was mapping CHILD as Entity (instead of component).
My current workaround is that I don't even map the relation at all, but query it "by hand" in the code and insert it into a transient child-List, but there has to be a better way...
Many thanks for any help!
zott
PS: Hibernate 3.1, Oracle 9