Joined: Fri May 19, 2006 7:01 pm Posts: 1 Location: Salt Lake City, UT USA
|
In Hibernate 3.1, I have a many-one relationship that I don't understand how to map. The essence of the problem is that there is one column in the database that is used both as:
1. A foreign key to a parent table (in the classic parent-child style).
2. Part of a compound foreign key to another table (a sibling table).
Since the column is used in multiple "many-to-one"s, I get a duplicate column definition when Hibernate initializes. There is no way to specify that the column in the compound key should not be cascaded on insert/update, and it needs to be cascaded on the parent FK. So, how can I map this relationship?
My current map (which does not work) is as follows:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="tp5.business.store.ProductPrice" table="ProductPrice">
<id name="productPriceId">
<generator class="identity" />
</id>
<version name="modifiedTime" type="timestamp" />
<property name="amount" />
<property name="isPercentage" />
<property name="useBasePrice" />
<property name="startDate" type="date" />
<property name="endDate" type="date" />
<!-- associations -->
<many-to-one name="seller" column="sellerId" />
<many-to-one name="buyer" column="buyerId" />
<many-to-one name="productLine" column="productLineId" />
<many-to-one name="product" column="productId" />
<many-to-one name="sku">
<column name="sellerId" />
<column name="sku" />
</many-to-one>
<many-to-one name="credential" column="credentialId" />
<many-to-one name="relationship" />
</class>
</hibernate-mapping>
The "sellerId" column is the duplicated one.
Thanks in advance for any help.
_________________ Joe Thomas
|
|