Hi, I'm using hibernate 3.2 and need some help setting up a mapping file that maps to a legacy database.
Schema:
Billing Table
PK contractId
FK billHistoryId
FK billHistorySuffixId
[rest of the columns]
BillingHistory Table
PK billHistoryId
PK billHistorySuffixId
PK, FK contractId
[rest of the columns]
I'm trying to map it in such a way that the Billing object has a getBillingHistory() method, which returns a BillingHistory object. billinghistory.hbm.xml (the mapping file for the history piece) is set up to have a composite-id of all three PK fields. This mapping should be one-to-one, with the history piece possibly nullable.
Things I've tried:
Mostly using one-to-many inside of sets, since one-to-one doesn't have much in the way of constraint options.
Code:
<properties name="billingHistoryId">
<property name="billHistoryId" column="billHistoryId" />
<property name="billHistorySuffixId" column="billHistorySuffixId" />
<property name="contractId" column="contractId" />
</properties>
...
<set name="billingHistory">
<key property-ref="billingHistoryId"/>
<one-to-many class="BillingHistory"/>
</set>
This fails because collection foreign key mapping has wrong number of columns: component[billHistoryId,billHistorySuffixId]
also have tried:
Code:
<set name="billingHistory">
<key>
<column name="billHistoryId" />
<column name="billHistorySuffixId" />
<column name="contractId" />
</key>
<one-to-many class="BillingHistory"/>
</set>
This fails saying the number of foreign key must have same number of columns as reference key.
Basically all I want is a mapping that outputs something analogous to:
Code:
select [columns] from Billing b
inner join BillingHistory bh
on b.contractId=bh.contractId
where b.billHistoryId = bh.billHistoryId
and b.billHistorySuffixId = bh.billHistorySuffixId;
Thanks for any pointers you can give me.