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