Hi,
I have a Customer class that is keyed on a composite primary key. This key is implemented as per the documented recommendations as a separate entity. The Customer class also contains a many-to-one mapping keyed on the composite key. This works fine. However, what I would like to do is add a property to the Customer class in a different table. So for instance I have a separate table containing a composite foreign key, and one or more property columns. Looking at the Hibernate Wiki, the Delegate pattern seems to be a perfect fit. However, how do I specify an id of "foreign" or "assigned" when using composite keys? Here is my Customer mapping - is this the right way to go about it?
<hibernate-mapping>
<class name="uk.co.blueyonder.dialup.dao.Customer" table="CMS_ACCOUNTS">
<!-- The composite key -->
<composite-id name="id" class="uk.co.blueyonder.dialup.dao.CustomerCompositeId">
<key-property name="accountNumber" type="integer" column="Account_Number" />
<key-property name="siteID" type="integer" column="Site_ID" />
</composite-id>
<property name="password" column="Cms_Password" type="string" length="20" />
<property name="serviceType" column="Service_Type" type="string" length="1" />
<property name="lastBillValue" column="Last_Bill_Value" type="float" />
<property name="lastBillDate" column="Last_Bill_Date" type="date" />
<!-- The one-to-many mapping -->
<set name="telephoneAccounts" table="CMS_TELEPHONES" cascade="all">
<key>
<column name="Account_Number" />
<column name="Site_ID" />
</key>
<one-to-many class="uk.co.blueyonder.dialup.dao.TelephoneAccount" />
</set>
<!-- Would like to be able to access this as Customer.getProvisionStatus() -->
<one-to-one name="provisionStatus" class="uk.co.blueyonder.dialup.dao.DialupData" constrained="true" cascade="all" outer-join="true"/>
</class>
<!-- Here is the entity to delegate to -->
<class name="uk.co.blueyonder.dialup.dao.DialupData"
table="Dialup_Data"
proxy="uk.co.blueyonder.dialup.dao.DialupData">
<composite-id name="id" class="uk.co.blueyonder.dialup.dao.CustomerCompositeId">
<key-property name="accountNumber" type="integer" column="Account_Number" />
<key-property name="siteID" type="integer" column="Site_ID" />
</composite-id>
<!-- and the desired property -->
<property name="provisionStatus" column="Provision_Status" type="char"/>
</class>
</hibernate-mapping>
|