-->
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.  [ 3 posts ] 
Author Message
 Post subject: FK must have same number of columns as the referenced PK
PostPosted: Wed Jan 04, 2006 11:14 am 
Newbie

Joined: Wed Jan 04, 2006 11:04 am
Posts: 2
I all, I'm very new to hibernate and I've generated my classes and mappings with AppFuse Generator [https://appfusegenerator.dev.java.net/].

I Hope that these informations are enought...

Thanks in advance

a.terreno

Hibernate version: hibernate-3.1

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class
name="com.beequality.model.other.Anagraficarisorse"
table="anagraficarisorse"
select-before-update="false"
dynamic-update="true"
dynamic-insert="true"
optimistic-lock="all"
>
<composite-id name="anagraficarisorsePK" class="com.beequality.model.other.tbl.AnagraficarisorsePK">
<key-property name="codazienda" column="CodAzienda" type="java.lang.String" length="4" />
<key-property name="codutente" column="CodUtente" type="java.lang.String" length="5" />
</composite-id>
<property
name="cognome"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="Cognome"
length="50"
not-null="false"
unique="false"
/>
<property
name="nome"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="Nome"
length="50"
not-null="false"
unique="false"
/>
<property
name="incarico"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="Incarico"
length="50"
not-null="false"
unique="false"
/>
<property
name="telefono"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="Telefono"
length="50"
not-null="false"
unique="false"
/>
<property
name="fax"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="Fax"
length="50"
not-null="false"
unique="false"
/>
<property
name="cellulare"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="Cellulare"
length="50"
not-null="false"
unique="false"
/>
<property
name="eMail"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="E_mail"
length="50"
not-null="false"
unique="false"
/>
<property
name="userid"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="UserId"
length="15"
not-null="true"
unique="false"
/>
<property
name="password"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="Password"
length="12"
not-null="true"
unique="false"
/>
<property
name="inizioattivita"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="InizioAttivita"
length="19"
not-null="false"
unique="false"
/>
<property
name="fineattivita"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="FineAttivita"
length="19"
not-null="false"
unique="false"
/>
<property
name="datacreazione"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="DataCreazione"
length="19"
not-null="false"
unique="false"
/>
<property
name="dataaggiornamento"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="DataAggiornamento"
length="19"
not-null="false"
unique="false"
/>
<!-- Imported bi-directional one-to-many association to Ruolorisorse -->
<set name="ruolorisorseGroup"
table="ruolorisorse"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
>
<key>
<column name="CodAzienda"/>
</key>
<one-to-many
class="com.beequality.model.other.Ruolorisorse"
/>
</set>

<!-- imported bi-directional many-to-one association to Aziende -->
<many-to-one
name="Aziende"
class="com.beequality.model.other.Aziende"
not-null="false"
update="false"
insert="false"
>
<column name="CodAzienda" />
</many-to-one>
<!-- imported bi-directional many-to-one association to Qualifiche -->
<many-to-one
name="Qualifiche"
class="com.beequality.model.other.Qualifiche"
not-null="false"
outer-join="auto"
>
<column name="Qualifica" />
<column name="CodAzienda" />
</many-to-one>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class
name="com.beequality.model.other.Ruolorisorse"
table="ruolorisorse"
select-before-update="false"
dynamic-update="true"
dynamic-insert="true"
optimistic-lock="all"
>
<composite-id name="ruolorisorsePK" class="com.beequality.model.other.tbl.RuolorisorsePK">
<key-property name="codazienda" column="CodAzienda" type="java.lang.String" length="4" />
<key-property name="codrisorsa" column="CodRisorsa" type="java.lang.String" length="5" />
<key-property name="codarea" column="CodArea" type="java.lang.String" length="5" />
<key-property name="funzione" column="Funzione" type="java.lang.String" length="10" />
</composite-id>
<property
name="iniziovalidita"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="InizioValidita"
length="19"
not-null="false"
unique="false"
/>
<property
name="finevalidita"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="FineValidita"
length="19"
not-null="false"
unique="false"
/>
<!-- imported bi-directional many-to-one association to Areeaziendali -->
<many-to-one
name="Areeaziendali"
class="com.beequality.model.other.Areeaziendali"
not-null="false"
update="false"
insert="false"
>
<column name="CodArea" />
<column name="CodAzienda" />
</many-to-one>
<!-- imported bi-directional many-to-one association to Funzioni -->
<many-to-one
name="Funzioni"
class="com.beequality.model.other.Funzioni"
not-null="false"
update="false"
insert="false"
>
<column name="Funzione" />
<column name="CodAzienda" />
</many-to-one>
<!-- exported bi-directional one-to-many association to Anagraficarisorse -->
<set name="anagraficarisorseGroup"
table="anagraficarisorse"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
>
<key>
<column name="CodAzienda"/>
</key>
<one-to-many
class="com.beequality.model.other.Anagraficarisorse"
/>
</set>

</class>
</hibernate-mapping>

Full stack trace of any exception that occurs:
BUILD FAILED
E:\prj\beequality\beequality\build.xml:691: Schema text failed: Foreign key (FKA55EB4E8BBE8627:anagraficarisorse [CodAzienda])) must have same number of columns as the referenced primary key (ruolorisorse [CodAzienda,CodRisorsa,CodArea,Funzione])

Name and version of the database you are using:
MySQL 5.0.17-nt


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 11:53 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:52 am
Posts: 52
Location: Zurich
The generated mapping documents are inconsistent either because the tool could not correctly identify the primary or foreign key definition, or they are not correctly defined in your current database:

The table "ruolorisorse" has a composite key with is made out of 4 columns.
Check if this is correct.
If so, the foreign key definition must be adapted (your mapping doc contains only one column: "CodAzienda").

See the following link for composite key examples:
http://www.hibernate.org/hib_docs/v3/reference/en/html/example-mappings.html#example-mappings-composite-key

Urs


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 7:24 am 
Newbie

Joined: Wed Jan 04, 2006 11:04 am
Posts: 2
Quote:
The table "ruolorisorse" has a composite key with is made out of 4 columns.
Check if this is correct.

Yes this is correct.

I'm right now talking with the DBA and he said that we'll drop the FK :-)

thx a lot.

the DBA sais that this is a "non identifying relation" and sometimes, somewhere it's not correctly handled by the DB.

ciao ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.