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: Identifier of an instance of XXX was altered from X to X
PostPosted: Wed Sep 03, 2008 6:44 pm 
Newbie

Joined: Wed Sep 03, 2008 6:26 pm
Posts: 3
Hey guys! I have a very simple application and I have stumble on a bug that I cant solve. I've red many sites about my problem but I cant seam to find out whats wrong:


I have two classes: Tema and TipoTema

Here is a snippet of Tema:
Code:
public class Tema implements util.ObjetoJSON {

   private int clave;
   private String detalle;
   private TipoTema tipo;
...


Here is the mapping:
Code:
<hibernate-mapping>
    <class name = "modelo.catalogo.Tema" table = "TBLENTTEM">
        <id name = "clave" column = "CVEENTTEM">
            <generator class = "sequence">
                <param name = "sequence">TBLENTTEM_SEQ</param>
            </generator>
        </id>
        <property name = "detalle" type = "java.lang.String" column = "NOMENTTEM"/>                 
      <many-to-one name = "tipo" class = "modelo.catalogo.TipoTema" column = "CLAVETEMA" cascade="save-update"/>
    </class>
</hibernate-mapping>


Here is a snippet of TipoTema:
Code:
public class TipoTema implements util.ObjetoJSON{

   private int clave;
   private String nombre;
   ...


Here is the mapping for TipoTema:
Code:
<hibernate-mapping>
    <class name = "modelo.catalogo.TipoTema" table = "TBLTIPTEM">
        <id name = "clave" column = "CVETIPTEM">
            <generator class = "sequence">
                <param name = "sequence">TBLTIPTEM_SEQ</param>
            </generator>
        </id>
        <property name = "nombre" type = "java.lang.String" column = "NOMTIPTEM"/>      
    </class>
</hibernate-mapping>


Pretty simple, no?. I have a container that has the update method:
Code:
public void update(Tema dato) throws DatoNoValidoException {
      laSession.clear();
      if(laSession.get(Tema.class, dato.getClave())!=null){
         Tema actualiza = (Tema)laSession.get(Tema.class, dato.getClave());
         actualiza.fromJSON(dato.toJSON().toString());
         laSession.beginTransaction();
         laSession.update(actualiza);
         laSession.getTransaction().commit();
         laSession.flush();
      }
      else{
         ...
      }   
   }



laSession is a session object obtained by:
Code:
util.Hibernate.getSessionFactory().openSession();



When I try to update the "detalle" atribute from Tema evrything is ok. When I try to update the TipoTema attribute. I get the folowing error:

Code:
org.hibernate.HibernateException: identifier of an instance of modelo.catalogo.TipoTema was altered from 1 to 6


NOTE: the "1" and the "6" is the "clave" (ID in spanish) of the TipoTema class.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 2:13 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Hibernate doesn't allow you change the ID of an existing entity. If you need to do that you should delete() the existing entity and the save() a new entity. But my guess is that this is not want to do, but that your are trying to change the Tema entity to point to a different TipoTema entity.

I think the problem is within the Tema.fromJSON() method. If I have to guess it seems like it is doing something like:

Code:
Tema.getTipoTema().setId(6)


when it should do:

Code:
Tema.setTipoTema(tipoTemaWithId6)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 10:25 am 
Newbie

Joined: Wed Sep 03, 2008 6:26 pm
Posts: 3
Thankyou for responding nordborg =)

Yes, the fromJSON is doing something like what you say. I'm fixing it to see if it helps.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 10:44 am 
Newbie

Joined: Wed Sep 03, 2008 6:26 pm
Posts: 3
Problem solved! Thanks so much for the help =) Not to sound gay or anything...but I love you!! ^^


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.