-->
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: Help with:org.hibernate.MappingException:must have same numb
PostPosted: Sat Feb 28, 2009 1:19 am 
Newbie

Joined: Sat Jan 24, 2009 3:43 pm
Posts: 2
Hey, does anyone knows why does GlassFish throws this exception:
org.hibernate.MappingException: Foreign key (FK4FDEDAA91B86637C:area_laboral [id_org_ubicacion])) must have same number of columns as the referenced primary key (organizacion_ubicacion [id_org_ubicacion,id_organizacion,id_pais,id_plaza])

Here are my mapping documents:
//////////////////OrganizacionUbicacion////////////////////////////////////////
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 27/02/2009 09:01:32 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="Pojos.OrganizacionUbicacion" table="organizacion_ubicacion" catalog="privilegios">
<composite-id name="id" class="Pojos.OrganizacionUbicacionId">
<key-property name="idOrgUbicacion" type="long">
<column name="id_org_ubicacion" />
</key-property>
<key-property name="idOrganizacion" type="long">
<column name="id_organizacion" />
</key-property>
<key-property name="idPais" type="long">
<column name="id_pais" />
</key-property>
<key-property name="idPlaza" type="string">
<column name="id_plaza" length="5" />
</key-property>
</composite-id>
<many-to-one name="pais" class="Pojos.Pais" update="false" insert="false" fetch="select">
<column name="id_pais" not-null="true" />
</many-to-one>
<many-to-one name="organizacion" class="Pojos.Organizacion" update="false" insert="false" fetch="select">
<column name="id_organizacion" not-null="true" />
</many-to-one>
<many-to-one name="plaza" class="Pojos.Plaza" update="false" insert="false" fetch="select">
<column name="id_plaza" length="5" not-null="true" />
</many-to-one>
<set name="areaLaborals" inverse="true">
<key>
<column name="id_org_ubicacion" not-null="true" />
</key>
<one-to-many class="Pojos.AreaLaboral" />
</set>
</class>
</hibernate-mapping>
//////////////////////////////Organizacion////////////////////////////////////////
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 27/02/2009 09:01:32 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="Pojos.Organizacion" table="organizacion" catalog="privilegios">
<id name="idOrganizacion" type="long">
<column name="id_organizacion" />
<generator class="assigned" />
</id>
<property name="nombreCorto" type="string">
<column name="nombre_corto" length="25" />
</property>
<property name="nombreLargo" type="string">
<column name="nombre_largo" length="150" not-null="true" />
</property>
<property name="altaStamp" type="timestamp">
<column name="alta_stamp" length="19" not-null="true" />
</property>
<property name="modificaStamp" type="timestamp">
<column name="modifica_stamp" length="19" />
</property>
<property name="bajaStamp" type="timestamp">
<column name="baja_stamp" length="19" />
</property>
<property name="calleNumero" type="string">
<column name="calle_numero" length="100" not-null="true" />
</property>
<property name="colonia" type="string">
<column name="colonia" length="100" not-null="true" />
</property>
<property name="municipio" type="string">
<column name="municipio" length="100" />
</property>
<property name="cp" type="string">
<column name="cp" length="10" not-null="true" />
</property>
<property name="telefono" type="string">
<column name="telefono" length="15" not-null="true" />
</property>
<set name="organizacionUbicacions" inverse="true">
<key>
<column name="id_organizacion" not-null="true" />
</key>
<one-to-many class="Pojos.OrganizacionUbicacion" />
</set>
</class>
</hibernate-mapping>
//////////////////////////////Plaza////////////////////////////////////////
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 27/02/2009 09:01:32 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="Pojos.Plaza" table="plaza" catalog="privilegios">
<id name="idPlaza" type="string">
<column name="id_plaza" length="5" />
<generator class="assigned" />
</id>
<property name="plaza" type="string">
<column name="plaza" length="45" not-null="true" />
</property>
<property name="altaStamp" type="timestamp">
<column name="alta_stamp" length="19" not-null="true" />
</property>
<property name="modificaStamp" type="timestamp">
<column name="modifica_stamp" length="19" />
</property>
<property name="bajaStamp" type="timestamp">
<column name="baja_stamp" length="19" />
</property>
<set name="plazaHorarios" inverse="true">
<key>
<column name="id_plaza" length="5" not-null="true" unique="true" />
</key>
<one-to-many class="Pojos.PlazaHorario" />
</set>
<set name="organizacionUbicacions" inverse="true">
<key>
<column name="id_plaza" length="5" not-null="true" />
</key>
<one-to-many class="Pojos.OrganizacionUbicacion" />
</set>
</class>
</hibernate-mapping>
/////////////////////////////////////////////////////////////////////////////////////
And here is mysql queries for creating the tables:

//////////////////////////////////Organizacion////////////////////////////////////
CREATE TABLE `privilegios`.`organizacion` (
`id_organizacion` bigint(20) unsigned NOT NULL,
`nombre_corto` varchar(25) default NULL,
`nombre_largo` varchar(150) NOT NULL,
`alta_stamp` datetime NOT NULL,
`modifica_stamp` datetime default NULL,
`baja_stamp` datetime default NULL,
`calle_numero` varchar(100) NOT NULL,
`colonia` varchar(100) NOT NULL,
`municipio` varchar(100) default NULL,
`cp` varchar(10) NOT NULL,
`telefono` varchar(15) NOT NULL,
PRIMARY KEY (`id_organizacion`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
//////////////////////////////////OrganizacionUbicacion/////////////////////////
CREATE TABLE `privilegios`.`organizacion_ubicacion` (
`id_org_ubicacion` bigint(20) unsigned NOT NULL,
`id_organizacion` bigint(20) unsigned NOT NULL,
`id_pais` bigint(20) unsigned NOT NULL,
`id_plaza` char(5) NOT NULL,
PRIMARY KEY (`id_org_ubicacion`,`id_organizacion`,`id_pais`,`id_plaza`),
KEY `FK_organizacion_ubicacion_1` (`id_organizacion`),
KEY `FK_organizacion_ubicacion_2` (`id_pais`),
KEY `FK_organizacion_ubicacion_3` (`id_plaza`),
CONSTRAINT `FK_organizacion_ubicacion_1` FOREIGN KEY (`id_organizacion`) REFERENCES `organizacion` (`id_organizacion`),
CONSTRAINT `FK_organizacion_ubicacion_2` FOREIGN KEY (`id_pais`) REFERENCES `pais` (`id_pais`),
CONSTRAINT `FK_organizacion_ubicacion_3` FOREIGN KEY (`id_plaza`) REFERENCES `plaza` (`id_plaza`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
///////////////////////////////////////Plaza////////////////////////////////////////
CREATE TABLE `privilegios`.`plaza` (
`id_plaza` char(5) NOT NULL,
`plaza` varchar(45) NOT NULL,
`alta_stamp` datetime NOT NULL,
`modifica_stamp` datetime default NULL,
`baja_stamp` datetime default NULL,
PRIMARY KEY (`id_plaza`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/////////////////////////////////////////////////////////////////////////////////////
By the way; I used netbeans reverse enginering for generating the hbm files.
So, does anyone knows where is the problem??


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 6:22 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Code:
<set name="areaLaborals" inverse="true">
<key>
<column name="id_org_ubicacion" not-null="true" />
</key>
<one-to-many class="Pojos.AreaLaboral" />
</set>


This <set> is mapped incorrectly. It is part of the Pojos.OrganizacionUbicacion class which has a composite primary key with four columns (id_org_ubicacion,id_organizacion,id_pais,id_plaza). This means that the <key> tag must also contain the same number of matching columns. Eg.

Code:
<key>
<column name="id_org_ubicacion" not-null="true" />
<column name="id_organizacion" not-null="true" />
<column name="id_pais" not-null="true" />
<column name="id_plaza" not-null="true" />
</key>


All of the four column must exist in table where you are storing Pojos.AreaLaboral entities. You are not showing the mapping (or table) for this class, but since the <set> is inverse I guess you already have a <many-to-one> going from Pojos.AreaLaboral to Pojos.OrganizacionUbicacion.


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.