-->
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: Mapping Exception
PostPosted: Mon Mar 25, 2013 8:11 am 
Newbie

Joined: Mon Mar 25, 2013 7:47 am
Posts: 1
Hi everybody,

I have a problem with my Hibernate Mapping. I have three files, each of them is the mapping of one hibernate class:

    Proyectos.hbm.xml: Proyectos class
    UnidadesEmpresa.hbm.xml: UnidadesEmpresa class
    CliUniEmps.hbm.xml; CliUniEmp class

I have a problem related with the last one. Its code is this:

Code:
<hibernate-mapping>
    <class name="com.dmsti.dominio.CliUniEmp" table="clientes_uniemps"  lazy="false" catalog="dms_hrm">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="identity" />
        </id>
       
      <many-to-one name="cliente" entity-name="com.dmsti.dominio.Cliente"
      column="cliente_id" unique="false" not-null="false" />
       
      <many-to-one name="unidadEmpresa" entity-name="com.dmsti.dominio.UnidadEmpresa"
      column="uniemp_id" unique="false" not-null="false" />

    </class>
</hibernate-mapping>


All the files are properly related by hibernate.cfg.xml and all of them usually work. Now let me explain my current problem deeply.

1. In my Hibernate file Proyectos.hbm.xml I have a reference to an entity called cliUniEmp which is defined bellow, in CliUniEmps.hbm.xml (and whose table is clientes_uniemps).

Code 1.
Code:
      <many-to-one name="cliUniEmp" entity-name="com.dmsti.dominio.CliUniEmp"
             column="cli_uniemp_id"  unique="false" not-null="false" />




2. In UnidadesEmpresa.hbm.xml there is another reference to the same table.

Code 2.
Code:
    <set name="clientes" table="clientes_uniemps"   catalog="dms_hrm"
             inverse="false" lazy="false" fetch="select" cascade="all" >
            <key>
                <column name="uniemp_id" not-null="true" />
            </key>
            <many-to-many entity-name="com.dmsti.dominio.Cliente">
                <column name="cliente_id" not-null="true" />
            </many-to-many>
             </set>     



3. Both codes work properly when just one of them exists. If I remove the set "clientes" (code 2) from UnidadesEmpresa.hbm.xml then the many-to-one entity "cliUniEmp" (code 1) works without any problems. In the same way, if I remove code 1 then code 2 works perfectly.

4. If both are at the same time in my application, Hibernate launch an exception:

Quote:
org.hibernate.MappingException: Foreign key (FKE442A80E4FB5975E:proyectos [cli_uniemp_id])) must have same number of columns as the referenced
primary key (clientes_uniemps [uniemp_id,cliente_id])


I became stuck! Please, can you help me?


Top
 Profile  
 
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.