Hello,
I need to map a link between two table where the foriegn key is not the primary key.
Table A (id, col1, col2, col3, col4) | (col1, col2, col3) is unique
Table B (id, col1, col2, col5) | (col1, col2) is unique
We got a link many to one between table A and B. I used "property-ref" and "properties" so I manage to defne the many to on relation.
For the other way relation, I define a "Set", but I can't find a good solution for the mapping on the key. It seems we can only used the primary key of the table. Is it true?
Code:
<hibernate-mapping>
<class name="TableA" table="TABLE_A" schema="MySchema">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="increment" />
</id>
<properties name="sec_key" unique="true">
<property name="col1" type="java.lang.Integer">
<column name="COL1" not-null="true" />
</property>
<property name="col2" type="java.lang.Short">
<column name="COL2" not-null="true" />
</property>
</properties>
...
Code:
<hibernate-mapping>
<class name="TableB" table="TABLE_B" schema="MySchema">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="increment" />
</id>
<many-to-one name="tableA" class="TableA" update="false" insert="false" fetch="select" property-ref="sec_key">
<column name="COL1" not-null="true" />
<column name="COL2" not-null="true" />
</many-to-one>
...
How to define the Set if Table A mapping?
Code:
<set name="tableBs" inverse="true">
<key ???????/>
<one-to-many class="TableB" />
</set>
Thanks.