title: Exception: Could not synchronize database state with session
body: <p>I have an web application developed on spring and hibernate 3.0 and deployed on apache tomcat 6.
  I am getting below error when I am trying to insert the data to the one of the table ('CAR_ATTRIBUTE' table).</p>
  
  <pre><code>    [CAR] [2010-12-12 13:41:30,651] ERROR [http-80-2] AbstractFlushingEventListener.performExecutions(301) | Could not synchronize database state with session
  org.hibernate.exception.ConstraintViolationException: could not insert: [com.test.model.CarAttribute]
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
          at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
          at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
          at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
          at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
          at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
          at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
         at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
          at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
          at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
          at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
          at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
          at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
          at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:558)
          at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662)
          at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632)
          at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:319)
          at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
          at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
          at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
          at $Proxy31.resyncAttributes(Unknown Source)
         ...
          at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
          at com.belk.car.app.webapp.controller.BaseFormController.processFormSubmission(BaseFormController.java:169)
          at com.belk.car.app.webapp.controller.DashBoardFormController.processFormSubmission(DashBoardFormController.java:176)
          at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
          at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
          at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
          at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
          at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
          at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
          at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
          at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
          at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:343)
          at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
          at org.appfuse.webapp.filter.StaticFilter.doFilterInternal(StaticFilter.java:102)
          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
          at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:164)
          at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
          at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
          at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:406)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.appfuse.webapp.filter.LocaleFilter.doFilterInternal(LocaleFilter.java:74)
          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265)
          at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
          at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:166)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
          at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
          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:175)
          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:263)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
          at java.lang.Thread.run(Thread.java:735)
  Caused by:
  java.sql.BatchUpdateException: ORA-00001: unique constraint (CARS.XAK1CAR_ATTRIBUTE) violated
  
          at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:602)
          at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9350)
          at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:210)
          at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
          at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
          at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:34)
          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2247)
          ... 96 more
  </code></pre>
  
  <p>This error is only reproducable at production environment. Same code is working on my local environment pointing to same DB.
  I tried adding logger statement and found that sequence generator is generating same value , i.e '0' each time.
  Awaiting for ur help.</p>
  
  <p>-- Sun2</p>
  
  <hr>
  
  <p>Thanks for reply. Yes, Exception clearly says its violating the constrains. CARS.XAK1CAR_ATTRIBUTE is combined key and it should be unique. I have validated all the data (by loggers) and could not found the data which can violate this constrains.  Moreover if it is violating this constrains then it should not work on my local  environment pointing to same DB. 
  Can this be server specific?
  I can provide more details like table DDL and data which I am trying to insert, If it can help to solve the issue. 
  --Santosh</p>