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.