-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Error:mapping multiple foreign to the same primary key
PostPosted: Thu May 06, 2004 3:34 pm 
Newbie

Joined: Thu May 06, 2004 3:08 pm
Posts: 3
Location: Portland, OR
There are 2 tables: order and profile
In table Order: there are 3 fields that has reference to table profile. How should I define the mapping in this situation.

I recieved a runtime error:
net.sf.hibernate.MappingException: Foreign key (ORDERTABLE [SHIPPING_PROFILE_ID_FK,BILLING_PROFILE_ID_FK,ORIGINATOR_PROFILE_ID_FK])) must have same number of columns as the referenced primary key (PROFILE [PROFILE_ID])

Here are the 2 hbm.xml files:
<?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>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="sonic.hibernate.Profile"
table="PROFILE"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="PROFILE"
</meta>

<id
name="profileId"
type="java.lang.Integer"
column="PROFILE_ID"
>
<meta attribute="field-description">
@hibernate.id
generator-class="hilo"
type="java.lang.Integer"
column="PROFILE_ID"

@hibernate.generator-param
name="table"
value="profilehilo"
@hibernate.generator-param
name="column"
value="next_value"
@hibernate.generator-param
name="max_lo"
value="100"
</meta>
<generator class="hilo">
<param name="table">profilehilo</param>
<param name="column">next_value</param>
<param name="max_lo">100</param>
</generator>
</id>

<property
name="title"
type="java.lang.String"
column="TITLE"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="TITLE"
length="30"
</meta>
</property>
<property
name="lastName"
type="java.lang.String"
column="LAST_NAME"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="LAST_NAME"
length="30"
</meta>
</property>
<property
name="firstName"
type="java.lang.String"
column="FIRST_NAME"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="FIRST_NAME"
length="30"
</meta>
</property>
<property
name="middleName"
type="java.lang.String"
column="MIDDLE_NAME"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="MIDDLE_NAME"
length="30"
</meta>
</property>
<property
name="company"
type="java.lang.String"
column="COMPANY"
length="80"
>
<meta attribute="field-description">
@hibernate.property
column="COMPANY"
length="80"
</meta>
</property>
<property
name="phone1"
type="java.lang.String"
column="PHONE_1"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="PHONE_1"
length="30"
</meta>
</property>
<property
name="addressLine1"
type="java.lang.String"
column="ADDRESS_LINE1"
not-null="true"
length="50"
>
<meta attribute="field-description">
@hibernate.property
column="ADDRESS_LINE1"
length="50"
not-null="true"
</meta>
</property>
<property
name="addressLine2"
type="java.lang.String"
column="ADDRESS_LINE2"
length="50"
>
<meta attribute="field-description">
@hibernate.property
column="ADDRESS_LINE2"
length="50"
</meta>
</property>
<property
name="city"
type="java.lang.String"
column="CITY"
not-null="true"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="CITY"
length="30"
not-null="true"
</meta>
</property>
<property
name="state"
type="java.lang.String"
column="STATE"
not-null="true"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="STATE"
length="30"
not-null="true"
</meta>
</property>
<property
name="country"
type="java.lang.String"
column="COUNTRY"
not-null="true"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="COUNTRY"
length="30"
not-null="true"
</meta>
</property>
<property
name="zip"
type="java.lang.String"
column="ZIP"
not-null="true"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="ZIP"
length="30"
not-null="true"
</meta>
</property>
<property
name="email1"
type="java.lang.String"
column="EMAIL_1"
length="255"
>
<meta attribute="field-description">
@hibernate.property
column="EMAIL_1"
length="255"
</meta>
</property>
<property
name="languagePref"
type="java.lang.String"
column="LANGUAGE_PREF"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="LANGUAGE_PREF"
length="10"
</meta>
</property>

<!-- associations -->
<!-- bi-directional one-to-many association to Ordertable -->
<set
name="ordertables"
lazy="true"
inverse="true"
>
<meta attribute="field-description">
@hibernate.set
lazy="true"
inverse="true"

@hibernate.collection-key
column="SHIPPING_PROFILE_ID_FK"
@hibernate.collection-key
column="BILLING_PROFILE_ID_FK"
@hibernate.collection-key
column="ORIGINATOR_PROFILE_ID_FK"

@hibernate.collection-one-to-many
class="sonic.hibernate.Ordertable"
</meta>
<key>
<column name="SHIPPING_PROFILE_ID_FK" />
<column name="BILLING_PROFILE_ID_FK" />
<column name="ORIGINATOR_PROFILE_ID_FK" />
</key>
<one-to-many
class="sonic.hibernate.Ordertable"
/>
</set>
</class>
</hibernate-mapping>

======================
<?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>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="sonic.hibernate.Ordertable"
table="ORDERTABLE"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="ORDERTABLE"
</meta>

<id
name="orderId"
type="java.lang.Integer"
column="ORDER_ID"
>
<meta attribute="field-description">
@hibernate.id
generator-class="hilo"
type="java.lang.Integer"
column="ORDER_ID"

@hibernate.generator-param
name="table"
value="ordertablehilo"
@hibernate.generator-param
name="column"
value="next_value"
@hibernate.generator-param
name="max_lo"
value="100"
</meta>
<generator class="hilo">
<param name="table">ordertablehilo</param>
<param name="column">next_value</param>
<param name="max_lo">100</param>
</generator>
</id>

<property
name="statusId"
type="int"
column="STATUS_ID"
not-null="true"
length="11"
>
<meta attribute="field-description">
@hibernate.property
column="STATUS_ID"
length="11"
not-null="true"
</meta>
</property>
<property
name="placementDate"
type="java.util.Date"
column="PLACEMENT_DATE"
not-null="true"
length="50"
>
<meta attribute="field-description">
@hibernate.property
column="PLACEMENT_DATE"
length="50"
not-null="true"
</meta>
</property>
<property
name="taxPrice"
type="java.math.BigDecimal"
column="TAX_PRICE"
not-null="true"
length="19"
>
<meta attribute="field-description">
@hibernate.property
column="TAX_PRICE"
length="19"
not-null="true"
</meta>
</property>
<property
name="shippingPrice"
type="java.math.BigDecimal"
column="SHIPPING_PRICE"
not-null="true"
length="19"
>
<meta attribute="field-description">
@hibernate.property
column="SHIPPING_PRICE"
length="19"
not-null="true"
</meta>
</property>
<property
name="subtotal"
type="java.math.BigDecimal"
column="SUBTOTAL"
not-null="true"
length="19"
>
<meta attribute="field-description">
@hibernate.property
column="SUBTOTAL"
length="19"
not-null="true"
</meta>
</property>
<property
name="total"
type="java.math.BigDecimal"
column="TOTAL"
not-null="true"
length="19"
>
<meta attribute="field-description">
@hibernate.property
column="TOTAL"
length="19"
not-null="true"
</meta>
</property>

<!-- associations -->
<!-- bi-directional one-to-many association to Orderitem -->
<set
name="orderitems"
lazy="true"
inverse="true"
>
<meta attribute="field-description">
@hibernate.set
lazy="true"
inverse="true"

@hibernate.collection-key
column="ORDER_ID_FK"

@hibernate.collection-one-to-many
class="sonic.hibernate.Orderitem"
</meta>
<key>
<column name="ORDER_ID_FK" />
</key>
<one-to-many
class="sonic.hibernate.Orderitem"
/>
</set>
<!-- bi-directional many-to-one association to Profile -->
<many-to-one
name="profile"
class="sonic.hibernate.Profile"
not-null="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="SHIPPING_PROFILE_ID_FK"
@hibernate.column name="BILLING_PROFILE_ID_FK"
@hibernate.column name="ORIGINATOR_PROFILE_ID_FK"
</meta>
<column name="SHIPPING_PROFILE_ID_FK" />
<column name="BILLING_PROFILE_ID_FK" />
<column name="ORIGINATOR_PROFILE_ID_FK" />
</many-to-one>

</class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.