-->
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.  [ 4 posts ] 
Author Message
 Post subject: Provided id of the wrong type??
PostPosted: Tue Mar 18, 2008 4:22 am 
Newbie

Joined: Mon Mar 17, 2008 4:26 am
Posts: 2
Hello:
I'm using hibernate in my application, and when i tried to load a object i have this exception:
Caused by: org.hibernate.TypeMismatchException: Provided id of the wrong type: Expected: class es.impl.Tabla2Id, got class es.impl.Tabla1Id
I'm so confuse, because I save with the same application the object i want to load, and everything was ok, so ¿why the id was right when i saved, but it's a wrong type when i load?

The hbm files are:

Tabla1.hbm.xml:
Code:

<class name="es.impl.Tabla1" table="Tabla1" schema="dbo" catalog="Catalog">
      <composite-id name="id" class="es.impl.Tabla1Id">
          <key-many-to-one name="tabla3" class="es.impl.Tabla3">
                <column name="idTabla3" />
          </key-many-to-one>
          <key-property name="nif" type="java.lang.String">
                <column name="NIF" length="9" />
          </key-property>
    </composite-id>
    <one-to-one name="tabla2" class="es.impl.Tabla2"/>
     <property name="hombres" type="java.lang.String">
            <column name="Hombres" not-null="true" />
     </property>
...
</class>

Tabla2.hbm.xml
Code:

<class name="es.impl.Tabla2" table="Tabla2" schema="dbo" catalog="Catalog">
     <composite-id name="id" class="es.impl.Tabla2Id">
          <key-many-to-one name="tabla1" class="es.impl.Tabla1">
                <column name="idTabla3" />
                <column name="NIF" length="9" />               
            </key-many-to-one>
    </composite-id>       
    ...
</class>

Tabla3.hbm.xml
Code:
<class name="es.impl.Tabla3" table="Tabla3" schema="dbo" catalog="Catalog">
     <id name="idTabla3" type="java.lang.Integer">
            <column name="idTabla3" />
            <generator class="identity" />
     </id>
     <set name="tabla1" inverse="true">
           <key>
           <column name="idTabla3" not-null="true" />
           </key>
          <one-to-many class="es.impl.Tabla1" />
    </set>
    .....
</class>


In the hava code, i search wih the Tabla3 class, and when i do:
Iterator<Tabla1> it = tabla3.getTabla1().iterator();
i got the exception... Really, i don't understand why, if i do a get of Tabla1, the hibernate exception expect a Tabla2Id.... Someone can help me, please?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 5:58 am 
Newbie

Joined: Mon Mar 17, 2008 4:26 am
Posts: 2
I change the mapped file Tabla1.hbm.xml, deleting the one-to-one relation and put a Set with a one-to-many relation and everything works, so if someone ave the same problem here is a solution... But if someone know why happen that, please explain it, because the relation is one-to-one... u don't understand why hibernate force me to put a one-to-many.

<class name="es.impl.Tabla1" table="Tabla1" schema="dbo" catalog="Catalog">
<composite-id name="id" class="es.impl.Tabla1Id">
<key-many-to-one name="tabla3" class="es.impl.Tabla3">
<column name="idTabla3" />
</key-many-to-one>
<key-property name="nif" type="java.lang.String">
<column name="NIF" length="9" />
</key-property>
</composite-id>
<set name="tabla2s" inverse="true">
<key>
<column name="idTabla3" not-null="true" />
<column name="NIF" not-null="true" />
</key>
<one-to-many class="es.impl.Tabla2" />
</set>
<property name="hombres" type="java.lang.String">
<column name="Hombres" not-null="true" />
</property>
...
</class>


Top
 Profile  
 
 Post subject: Re: Provided id of the wrong type??
PostPosted: Thu Jul 15, 2010 9:39 am 
Newbie

Joined: Thu Jul 15, 2010 9:36 am
Posts: 1
You should check the file mapping and the JavaBean, there may be some property that you are not specifying the object (JavaBean), and the mapping file are taking another property type (wrong)
*Spanish:
Tu debes revisar el archivo de mapeo y el JavaBean, puede haber alguna propiedad que no le estes especificando en el objeto(JavaBean), y el archivo de mapeo este tomando el tipo de otra propiedad(erroneo).


Top
 Profile  
 
 Post subject: Re: Provided id of the wrong type??
PostPosted: Fri May 20, 2011 5:16 am 
Newbie

Joined: Fri May 20, 2011 5:07 am
Posts: 1
The problem seems to be in the composite id class name.

In a one-to-one relation, hibernate wants that the composite-id classes are exactly the same in both related objects.

I had the same error in a similar case:

Code:
<hibernate-mapping>
    <class name="org.test.Object1" table="TABLE1">
        <composite-id name="id" class="org.test.Object1Id">
            <key-property name="counter" type="integer">
                <column name="COUNTER" />
            </key-property>
            <key-property name="uuid" type="java.lang.String">
                <column name="UUID" length="16" />
            </key-property>
        </composite-id>
        ...
</hibernate-mapping>

<hibernate-mapping>
    <class name="org.test.Object2" table="TABLE2">
        <composite-id name="id" class="org.test.Object2Id">
            <key-property name="counter" type="integer">
                <column name="COUNTER" />
            </key-property>
            <key-property name="uuid" type="java.lang.String">
                <column name="UUID" length="16" />
            </key-property>
        </composite-id>
        ...
</hibernate-mapping>


and changing org.test.Object2Id class with org.test.Object1Id one, the problem seems to be solved.


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