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:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 12/06/2014 12:52:29 PM by Hibernate Tools 3.6.0 -->
<hibernate-mapping>
<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>
<key-property name="idUsuario" type="string">
<column name="idUsuario" length="30" />
</key-property>
</composite-id>
<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>
<property name="nombreCompleto" type="string">
<column name="nombreCompleto" length="70" not-null="true" />
</property>
<property name="usuarioActivo" type="boolean">
<column name="usuario_activo" not-null="true" />
</property>
<property name="correoElectronico" type="string">
<column name="correoElectronico" length="80" not-null="true" />
</property>
<set name="admRoleses" table="adm_roles_usuarios" inverse="false" lazy="true" fetch="select">
<key>
<column name="tipoId" not-null="true" />
<column name="idUsuario" length="30" not-null="true" />
</key>
<many-to-many entity-name="entidades.AdmRoles">
<column name="idRol" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
Any help will be appreciated