-->
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.  [ 2 posts ] 
Author Message
 Post subject: MappingException: Foreign key must have same number of colum
PostPosted: Fri Sep 24, 2004 5:36 am 
Newbie

Joined: Wed Sep 15, 2004 9:35 am
Posts: 13
Hi, I have the following error by mapping this hbn.xml file:

DEBUG - resolving reference to class: de.XXX.asr.businessmodel.PrNrBasismodell
net.sf.hibernate.MappingException: Foreign key (PRNRBASISMODELL_LAND [ID_PRNR_BASISMODELL])) must have same number of columns as the referenced primary key (PRNR_BASISMODELL [BASISMODELL_ID,ID_LAND])
at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60)
at net.sf.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:691)
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:666)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:784)
at de.XXX.asr.persistence.AbstractHibernateManager.<init>(AbstractHibernateManager.java:34)
at de.XXX.asr.persistence.BauteilManager.<init>(BauteilManager.java:18)
at test.Main.main(Main.java:43)
java.lang.NullPointerException
at de.XXX.asr.persistence.AbstractHibernateManager.load(AbstractHibernateManager.java:91)
at test.Main.main(Main.java:47)
Exception in thread "main"


this is the hbn. xml file:

<?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="de.XXX.asr.businessmodel.PrNrBasismodellLand" table="PRNRBASISMODELL_LAND">
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">SEQ_PRNRBASISMODELL_LAND</param>
</generator>
</id>

<many-to-one name="land" column="ID_LAND" class="de.XXX.asr.businessmodel.Land"/>
<many-to-one name="prNrBasismodell" column="ID_PRNR_BASISMODELL" class="de.XXX.asr.businessmodel.PrNrBasismodell"/>

<property name="standardKz" column="STANDARD_KZ"/>
<property name="us" column="US"/>
<property name="ts" column="TS"/>
</class>

</hibernate-mapping>


and here the PrNrBasismodell mapping file:

<?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="de.XXX.asr.businessmodel.PrNrBasismodell" table="PRNR_BASISMODELL">
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">SEQ_PRNR_BASISMODELL</param>
</generator>
</id>

<many-to-one name="basismodell" column="BASISMODELL_ID" class="de.XXX.asr.businessmodel.Basismodell"/>
<many-to-one name="prNrFamilie" column="ID_PRNR_FAMILIE" class="de.XXX.asr.businessmodel.PrNrFamilie"/>

<set name="prNrBasismodellLaender">
<key column="ID_PRNR_BASISMODELL"/>
<one-to-many class="de.XXX.asr.businessmodel.PrNrBasismodellLand"/>
</set>

<property name="prNrBezeichnung" column="PRNR_BEZ"/>
<property name="gewicht" column="GEWICHT"/>
<property name="us" column="US"/>
<property name="ts" column="TS"/>
</class>

</hibernate-mapping>



can somebody help me?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 24, 2004 7:32 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Quote:
Foreign key (PRNRBASISMODELL_LAND [ID_PRNR_BASISMODELL])) must have same number of columns as the referenced primary key (PRNR_BASISMODELL [BASISMODELL_ID,ID_LAND])

Please, check SQL scripts where you creates primary key for PRNR_BASISMODELL table, as I understand it is composite [BASISMODELL_ID,ID_LAND], but you tries to reference it using only ID_PRNR_BASISMODELL. Is it correct?

If your SQL script is correct, I guess, the problem is in the following mapping:
Code:
<class name="de.XXX.asr.businessmodel.PrNrBasismodellLand" table="PRNRBASISMODELL_LAND">
...
    <many-to-one name="prNrBasismodell" column="ID_PRNR_BASISMODELL" class="de.XXX.asr.businessmodel.PrNrBasismodell"/>

try this
Code:
<class name="de.XXX.asr.businessmodel.PrNrBasismodellLand" table="PRNRBASISMODELL_LAND">
...
    <many-to-one name="prNrBasismodell" column="ID_PRNR_BASISMODELL" class="de.XXX.asr.businessmodel.PrNrBasismodell" property-ref="corresponding-property-of-PrNrBasismodell-class"/>


And if it is possible, don't use natural (composite) primary keys for your business entities.

_________________
Leonid Shlyapnikov


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

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.