I have searched in the book Hibernate in Action, the online documentation and mapping examples, but could not find something which would resemble my problem.
I am maping an existing relational model to use with Hibernate. Its structure was done some years ago and some of it is a real challange to map. This is one of those challanges:
The Class automTrans references two records in AutomStCtxt which has two columns as primary key (composite id).
However, automTrans shares one column (context_code) with the two references.
I have tried two mapping options:
1)
<many-to-one name="automatonStateContext" class="com.audaxys.be.autom.dom.AutomatonStateContext">
<column name="fnl_automst_code" not-null="true" />
<column name="context_code" not-null="true" />
</many-to-one>
<many-to-one name="initialAutomatonStateCode" class="com.audaxys.be.autom.dom.AutomatonStateContext">
<column name="ini_automst_code" not-null="true" />
<column name="context_code" not-null="true" />
</many-to-one>
2)
<many-to-one name="automatonStateContext" class="com.audaxys.be.autom.dom.AutomatonStateContext">
<column name="fnl_automst_code" not-null="true" />
<column name="context_code" not-null="true" />
</many-to-one>
<property name="initialAutomatonStateCode" type="com.audaxys.fw.dom.usertype.TrimmedStringUserType">
<column name="ini_automst_code" not-null="true" />
</property>
The first option throws a mapping exception because the column context code is used twice. And the second option throws an exception in the insert statement because the foreign key automtrans_fk3 is not met.
Help is much needed, if you can.
Many thanks