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: Help:MappingException:FK,columns #,even when its the right 1
PostPosted: Mon Jun 16, 2014 4:33 pm 

Joined: Mon Jun 16, 2014 4:02 pm
Posts: 1
this is my first post on the page and I am working on Netbeans 8 with mysql and hibernate and I used the hibernate tool for the mapping. And I get this error: Caused by: org.hibernate.MappingException: Foreign key (FK_4s7nihascmjcx73pa1244h9fi:adm_roles_usuarios [tipoId])) must have same number of columns as the referenced primary key (adm_usuariosgeneral [tipoId,idUsuario])

The tables have the following structure on the DB: Table admUsuariosgeneral: tipoId, idUsuario(both PK and also FK to other table, they are the primary keys of that other table) and has other columns that arent important here.

Table adm_roles_usuarios: tipoId, idUsuario, idRol (all of them PK. tipoId and idUsuario are FK to admUsuariosgeneral and idRol FK to other table; idRol is the PK of that other table)

So as you can see the error is because of the FK in adm_roles_usuarios but that FK has both key atributes of the admUsuariosgeneral table.

Here I post the mapping of admUsuariosgeneral (Netbeans didnt generate a mapping for adm_roles_usuarios) in which if Im not wrong I can see the FKs defined correctly:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<!-- Generated 12/06/2014 12:52:29 PM by Hibernate Tools 3.6.0 -->
    <class name="entidades.AdmUsuariosgeneral" table="adm_usuariosgeneral" catalog="sigef">
        <composite-id name="id" class="entidades.AdmUsuariosgeneralId">
            <key-property name="tipoId" type="int">
                <column name="tipoId" />
            <key-property name="idUsuario" type="string">
                <column name="idUsuario" length="30" />
        <one-to-one name="personaPersonas" class="entidades.PersonaPersonas" constrained="true"></one-to-one>
        <property name="contrasenia" type="string">
            <column name="contrasenia" length="20" not-null="true" />
        <property name="nombreCompleto" type="string">
            <column name="nombreCompleto" length="70" not-null="true" />
        <property name="usuarioActivo" type="boolean">
            <column name="usuario_activo" not-null="true" />
        <property name="correoElectronico" type="string">
            <column name="correoElectronico" length="80" not-null="true" />
        <set name="admRoleses" table="adm_roles_usuarios" inverse="false" lazy="true" fetch="select">
                <column name="tipoId" not-null="true" />
                <column name="idUsuario" length="30" not-null="true" />
            <many-to-many entity-name="entidades.AdmRoles">
                <column name="idRol" not-null="true" />

Any help will be appreciated

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.