-->
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.  [ 1 post ] 
Author Message
 Post subject: Could not synchronize database state with session
PostPosted: Fri Oct 23, 2009 3:55 pm 
Newbie

Joined: Thu Aug 06, 2009 5:17 pm
Posts: 1
Hi hibernate users !

The problem arises when the line 84 inside the next method of the class AdminPaciente executes:
Code:
    public Paciente
    consultar(Session session, Documento doc)
    {
       Paciente paciente = null ;
       java.util.List listPacientes = null ;       
        try {
          
           Query query =
               session.createQuery("FROM Paciente pac WHERE pac.tipoDocumento = :tipoDocumento AND pac.numDocumento = :numDocumento");
          
           query.setString("tipoDocumento", doc.getTipo() );
           query.setString("numDocumento", doc.getNumero() );
          
           logger.info("consultar: ANTES de query.list()");
          
           listPacientes = query.list();  /*** line 84 ***/
           logger.info("consultar: DESPUES de query.list()");          
          
           if ( ( listPacientes != null ) && (listPacientes.size()==1) ) {
              paciente = (Paciente) listPacientes.get(0);
           }
          
           logger.info("consultar: FINALIZANDO bloque try");
          
        }
        catch(org.hibernate.StaleStateException staleExc) {
           logger.error("consultar: bloque catch org.hibernate.StaleStateException");           
           staleExc.printStackTrace();
           
        }       
        catch(Exception exc) {
           exc.printStackTrace();
        }
        finally {
        }   
        return paciente ;
    }       


The stack trace is the following:

Code:
2009-10-23 14:10:03,093 INFO  [STDOUT] 14:10:03,093  INFO DAOConsolidadoOrdenS:170 - importarConsolidadoOrdenesSEntreDosFechas: INICIO
2009-10-23 14:10:03,109 INFO  [STDOUT] 14:10:03,093  INFO DAOConsolidadoOrdenS:171 - importarConsolidadoOrdenesSEntreDosFechas: pathAbsoluto >>C:\01_CREADOS\ConsolidadoOrdenServicio-01_Sep_2009-30_Sep_2009.xml<<
2009-10-23 14:10:03,296 INFO  [STDOUT] 14:10:03,296  INFO AdminPaciente:316 - extraerPaciente: Fecha Creacion Paciente strFCP >>14-Sep-2009 12:00:00 -0500
2009-10-23 14:10:03,296 INFO  [STDOUT] 14:10:03,296  INFO AdminPaciente:320 - extraerPaciente: ANTES de sdf.parse(strFCP)
2009-10-23 14:10:03,296 INFO  [STDOUT] 14:10:03,296  INFO AdminPaciente:326 - extraerPaciente: DESPUES de sdf.parse(strFCP)
2009-10-23 14:10:03,296 INFO  [STDOUT] 14:10:03,296  INFO AdminPaciente:188 - importarPacientesEnBD: pac.getNumDocumento >>79002<<
2009-10-23 14:10:03,750 ERROR [STDERR] 23/10/2009 02:10:03 PM org.slf4j.impl.JDK14LoggerAdapter fillCallerData
INFO: cleaning up connection pool: jdbc:mysql://localhost:3306/oservicio
2009-10-23 14:10:04,046 INFO  [STDOUT] 14:10:04,046  INFO AdminPaciente:82 - consultar: ANTES de query.list()
2009-10-23 14:10:04,109 INFO  [STDOUT] 14:10:04,109  INFO AdminPaciente:85 - consultar: DESPUES de query.list()
2009-10-23 14:10:04,109 INFO  [STDOUT] 14:10:04,109  INFO AdminPaciente:91 - consultar: FINALIZANDO bloque try
2009-10-23 14:10:04,109 INFO  [STDOUT] 14:10:04,109  INFO AdminPaciente:121 - actualizarPaciente: ANTES de session.save
2009-10-23 14:10:04,140 INFO  [STDOUT] 14:10:04,140  INFO AdminPaciente:136 - actualizarPaciente: DESPUES de session.save
2009-10-23 14:10:04,140 INFO  [STDOUT] 14:10:04,140  INFO AdminPaciente:138 - actualizarPaciente: ANTES de commit()
2009-10-23 14:10:04,140 INFO  [STDOUT] 14:10:04,140  INFO AdminPaciente:316 - extraerPaciente: Fecha Creacion Paciente strFCP >>22-Sep-2009 12:00:00 -0500
2009-10-23 14:10:04,140 INFO  [STDOUT] 14:10:04,140  INFO AdminPaciente:320 - extraerPaciente: ANTES de sdf.parse(strFCP)
2009-10-23 14:10:04,140 INFO  [STDOUT] 14:10:04,140  INFO AdminPaciente:326 - extraerPaciente: DESPUES de sdf.parse(strFCP)
2009-10-23 14:10:04,140 INFO  [STDOUT] 14:10:04,140  INFO AdminPaciente:188 - importarPacientesEnBD: pac.getNumDocumento >>79004<<
2009-10-23 14:10:04,140 INFO  [STDOUT] 14:10:04,140  INFO AdminPaciente:82 - consultar: ANTES de query.list()
2009-10-23 14:10:04,187 ERROR [STDERR] 23/10/2009 02:10:04 PM org.hibernate.jdbc.BatchingBatcher doExecuteBatch
GRAVE: Exception executing batch:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
   at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)
   at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
   at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
   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 framework.ordenservicio.empresas.AdminPaciente.consultar(AdminPaciente.java:84)
   at framework.ordenservicio.empresas.AdminPaciente.actualizarPaciente(AdminPaciente.java:119)
   at framework.ordenservicio.empresas.AdminPaciente.importarPacientesEnBD(AdminPaciente.java:190)
   at framework.ordenservicio.dao.DAOConsolidadoOrdenS.importarConsolidadoOrdenesSEntreDosFechas(DAOConsolidadoOrdenS.java:207)
   at framework.ordenservicio.action.DesplegarArchivosPendientesPorCargarActions.cargar(DesplegarArchivosPendientesPorCargarActions.java:52)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
   at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
   at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
   at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
   at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
   at javax.faces.component.UICommand.broadcast(UICommand.java:387)
   at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:755)
   at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
   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:230)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
   at java.lang.Thread.run(Thread.java:595)
2009-10-23 14:10:04,187 ERROR [STDERR] 23/10/2009 02:10:04 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
GRAVE: Could not synchronize database state with session
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
   at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)
   at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
   at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
   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 framework.ordenservicio.empresas.AdminPaciente.consultar(AdminPaciente.java:84)
   at framework.ordenservicio.empresas.AdminPaciente.actualizarPaciente(AdminPaciente.java:119)
   at framework.ordenservicio.empresas.AdminPaciente.importarPacientesEnBD(AdminPaciente.java:190)
   at framework.ordenservicio.dao.DAOConsolidadoOrdenS.importarConsolidadoOrdenesSEntreDosFechas(DAOConsolidadoOrdenS.java:207)
   at framework.ordenservicio.action.DesplegarArchivosPendientesPorCargarActions.cargar(DesplegarArchivosPendientesPorCargarActions.java:52)


The problem arises when the method AdminPaciente.consultar is executed at the second time in the same transaction.
Event 1: A select is executed on the empty table "Pacientes"
Event 2: The java command "session.update( paciente );" is executed.
Event 3: A select is executed on the empty table "Pacientes". This "SELECT" is executed inside the method AdminPaciente.consultar. Then when the java command "query.list()" (at line 84) executes the exception is thrown.

Any help or insigth is really appreciated.

Ricardo De la Rosa (Colombia)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.