Hi there:
Following situation:
Table ProductOrder has a PK that looks like this:
OrderID
CategoryID
ProductID
Table Product has a PK like this:
CategoryID
ProductID
I want to define a one-to-one association between them via the PKs "CategoryID" and "ProductID".
When I try to do so, I get the following error:
MappingException: invalid join columns for association: Product
The reason for this error is basicly clear: I have to tell hibernate which columns to join
with. But how can I do this?
Here my mapping files for the tables:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.iag.ProductOrder"
table="product_order" lazy="true">
<composite-id>
<key-property name="OrderId" column="order_id" type="integer"/>
<key-property name="CategoryId" column="category_id" type="integer"/>
<key-property name="ProductId" column="product_id" type="integer"/>
</composite-id>
<version name="modified"
unsaved-value="undefined"/>
<property name="Text" column="text" type="string" not-null="false"/>
<many-to-one name="CustomerOrder" column="order_id" not-null="false"
insert="false" update="false"/>
<one-to-one name="Product" class="com.iag.Product"/>
</class>
</hibernate-mapping>
And for the Product:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.iag.Product"
table="product">
<composite-id>
<key-property name="CategoryId" column="category_id" type="integer"/>
<key-property name="ProductId" column="product_id" type="integer"/>
</composite-id>
<version name="modified"
unsaved-value="undefined"/>
<property name="CategoryId" column="category_id" type="integer" not-null="true"
insert="false" update="false"/>
<property name="ProductId" column="product_id" type="integer" not-null="true"
insert="false" update="false"/>
<property name="Name" column="name" type="string" not-null="true"/>
<property name="Price" column="price" type="double" not-null="false"/>
<property name="Type" column="type" type="string" not-null="true"/>
</class>
</hibernate-mapping>
Thx for any help.
Regards,
noips