-->
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.  [ 3 posts ] 
Author Message
 Post subject: joined-subclass and StaleObjectStateException
PostPosted: Tue Jul 14, 2009 1:47 pm 
Newbie

Joined: Tue Jan 25, 2005 11:53 am
Posts: 8
Hello,

I'm trying to save an object of this class:

Code:
public class Profesor extends Persona {

   private Dedicacion dedicacion;
   private UnidadOrganizacional unidadOrganizacional;
   private Date fechaIngreso;
....
}


This is the class it extends:

Code:
public class Persona extends Entidad {

   private TipoDocumento tipoDocumento;
   private String numeroDocumento;
   private String primerNombre;
   private String segundoNombre;
   private String primerApellido;
   private String segundoApellido;
   private String estadoCivil;
   private String grupoSanguineo;
   private String genero;
   private Date fechaNacimiento;
   private Long telefono;
   private Long movil;
   private String email;
   private String direccion;
   private Municipio municipioVivienda;
...
}


this is the mapping file:

Code:
<hibernate-mapping>
   <class name="sendero.persona.Persona" table="t_personas">
      <id name="id" column="id_persona">
         <generator class="sequence">
            <param name="sequence">t_personas_id_persona_seq</param>
         </generator>
      </id>
      <property name="numeroDocumento" column="doc_persona"/>
      <property name="primerApellido" column="primer_apellido"/>
      <property name="segundoApellido" column="segundo_apellido"/>
      <property name="primerNombre" column="primer_nombre"/>
      <property name="segundoNombre" column="segundo_nombre"/>
      <property name="estadoCivil" column="estado_civil"/>
      <property name="grupoSanguineo" column="grupo_rh"/>
      <property name="genero" column="genero"/>
      <property name="fechaNacimiento" column="fecha_nace"/>
      <property name="telefono" column="fijo"/>
      <property name="email" column="email"/>
      <property name="movil" column="movil"/>
      <property name="direccion" column="direccion_vive"/>
      <many-to-one name="tipoDocumento" class="sendero.documento.TipoDocumento" column="tipo_documento"/>
      <many-to-one name="municipioVivienda" class="sendero.lugar.Municipio" column="municipio_vive"/>

      <joined-subclass name="sendero.persona.Profesor" table="t_profesores">
         <key column="id_persona"/>
         <property name="fechaIngreso" column="fecha_ingreso"/>
         <many-to-one name="dedicacion" class="sendero.persona.Dedicacion" column="dedicacion"/>
         <many-to-one name="unidadOrganizacional" class="sendero.persona.UnidadOrganizacional" column="unidad_organizacional"/>
      </joined-subclass>
      
   </class>
</hibernate-mapping>


In my app, sometimes a Person is saved, and later it needs to became a Profesor, but when i try to save it using this:

Code:
.....
      profesor.setId(persona.getId());
      session.clear();
      new PersonaHelper().bind(profesor, request, session);
      session.saveOrUpdate(profesor);
      hql = session.createQuery("from Profesor p order by p.primerApellido, p.segundoApellido, " +
            "p.primerNombre, p.segundoNombre");
      model.put("profesores", hql.list());


When debugging, I'm getting this exception that's triggered in the last line:

Code:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [sendero.persona.Profesor#13]
   at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1792)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2435)
   at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2335)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2635)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
   at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)
   at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:996)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1141)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   at sendero.action.EditProfesorAction.perform(EditProfesorAction.java:80)
   at sendero.controllers.SenderoController.processRequest(SenderoController.java:67)
   at sendero.controllers.SenderoController.doPost(SenderoController.java:55)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at sendero.filters.AznFilter.doFilter(AznFilter.java:43)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:619)


I've tried with methods clear, evict and close from the Session. It just changes the exception i get but doesn't helps me to do the job. I've searched the forum, but I haven't found anything that can helps me.

I'm using Hibernate 3.3.1.

Thanks in advance for your help,

Juan Gabriel Romero Silva


Top
 Profile  
 
 Post subject: Re: joined-subclass and StaleObjectStateException
PostPosted: Tue Jul 14, 2009 3:54 pm 
Newbie

Joined: Tue Jan 25, 2005 11:53 am
Posts: 8
BTW

I forget to mention some really important thing:

if I omit the
Code:
session.clear();


I get this exception, fired in the saveOrUpdate line:

Code:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [sendero.persona.Profesor#13]
   at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:613)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:307)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:246)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:112)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
   at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:526)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:522)
   at sendero.action.EditProfesorAction.perform(EditProfesorAction.java:73)
   at sendero.controllers.SenderoController.processRequest(SenderoController.java:67)
   at sendero.controllers.SenderoController.doPost(SenderoController.java:55)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at sendero.filters.AznFilter.doFilter(AznFilter.java:43)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:619)


Any ideas on how can I do this?

Thanks,

Juan Gabriel Romero Silva


Top
 Profile  
 
 Post subject: Re: joined-subclass and StaleObjectStateException
PostPosted: Tue Jul 14, 2009 6:05 pm 
Newbie

Joined: Tue Jan 25, 2005 11:53 am
Posts: 8
Finally I believe I get what was happening:

When I try to saveOrUpdate, if the Profesor Object has an id, hibernate tries to update both rows (Persona and Profesor). If it finds only row for Persona, but doesn't find any row for Profesor, it assumes that "Row was updated or deleted by another transaction", and launches the corresponding exception.

To solve it, I've got to make some ugly things....
1. If there are some row for persona, but not any row for profesor, save an empty row for profesor (I've done this with SQLQuery).
2. clear the session
3. continue with saveOrUpdate for profesor

I'm believing what I've done may have some design flaws

Anyway, by now it was solved.

Thanks,

Juan Gabriel Romero Silva


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