-->
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.  [ 6 posts ] 
Author Message
 Post subject: Exception: Could not synchronize database state with session
PostPosted: Tue Dec 14, 2010 11:49 am 
Newbie

Joined: Tue Dec 14, 2010 11:31 am
Posts: 4
Hi,

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).
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


This error is only reproducable at production environment. Same code is working on my local environment pointing to same DB.

Is there any apache tomcat realated problem? Or sequence generator of the table.
Awaiting for ur help.

-- Sun2


Top
 Profile  
 
 Post subject: Re: Exception: Could not synchronize database state with session
PostPosted: Thu Dec 16, 2010 12:29 pm 
Newbie

Joined: Tue Dec 14, 2010 11:31 am
Posts: 4
I tried adding some logger statement to see what my application trying to insert in DB.
Surprisingly I found that, Its generating same primary key (sequence) each time.
If i initialize primary key variable to '-1' in my annotations class fie, its generating sequence -1 each time.
I am still not able to figure out what went wrong.
Please help!!


Top
 Profile  
 
 Post subject: Re: Exception: Could not synchronize database state with session
PostPosted: Fri Dec 17, 2010 7:14 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
Can you please post your model?? So that it will be easy to know where the problem is..

_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
 Post subject: Re: Exception: Could not synchronize database state with session
PostPosted: Fri Dec 17, 2010 4:28 pm 
Newbie

Joined: Tue Dec 14, 2010 11:31 am
Posts: 4
Here is my model CarAttribute class for car_attribute table:
Code:
package com.belk.car.app.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "CAR_ATTRIBUTE", uniqueConstraints = @UniqueConstraint(columnNames = {
      "CAR_ID", "ATTR_ID" }))
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include="all")
public class CarAttribute extends BaseAuditableModel implements
      java.io.Serializable {

   /**
    *
    */
   private static final long serialVersionUID = -4068641848151002886L;
   private long carAttrId;
   private Car car;
   private Attribute attribute;
   private AttributeValueProcessStatus attributeValueProcessStatus;
   private String attrValue;
   private String hasChanged;
   private String isChangeRequired;
   private String statusCd;
   private short displaySeq;

   public CarAttribute() {
   }

   
   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CAR_ATTRIBUTE_SEQ_GEN")
   @javax.persistence.SequenceGenerator(name = "CAR_ATTRIBUTE_SEQ_GEN", sequenceName = "CAR_ATTRIBUTE_SEQ", allocationSize = 1)
   @Column(name = "CAR_ATTR_ID", unique = true, nullable = false, precision = 12, scale = 0)
   public long getCarAttrId() {
      return this.carAttrId;
   }

   public void setCarAttrId(long carAttrId) {
      this.carAttrId = carAttrId;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "CAR_ID", nullable = false)
   public Car getCar() {
      return this.car;
   }

   public void setCar(Car car) {
      this.car = car;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "ATTR_ID", nullable = false)
   public Attribute getAttribute() {
      return this.attribute;
   }

   public void setAttribute(Attribute attribute) {
      this.attribute = attribute;
   }

   @Column(name = "ATTR_VALUE", length = 2000)
   public String getAttrValue() {
      return this.attrValue;
   }

   public void setAttrValue(String attrValue) {
      this.attrValue = attrValue;
   }

   @Column(name = "HAS_CHANGED", nullable = false, length = 1)
   public String getHasChanged() {
      return this.hasChanged;
   }

   public void setHasChanged(String hasChanged) {
      this.hasChanged = hasChanged;
   }

   @Column(name = "IS_CHANGE_REQUIRED", nullable = false, length = 1)
   public String getIsChangeRequired() {
      return this.isChangeRequired;
   }

   public void setIsChangeRequired(String isChangeRequired) {
      this.isChangeRequired = isChangeRequired;
   }

   @Column(name = "STATUS_CD", nullable = false, length = 20)
   public String getStatusCd() {
      return this.statusCd;
   }

   public void setStatusCd(String statusCd) {
      this.statusCd = statusCd;
   }

   @Column(name = "DISPLAY_SEQ", nullable = false, precision = 4, scale = 0)
   public short getDisplaySeq() {
      return this.displaySeq;
   }

   public void setDisplaySeq(short displaySeq) {
      this.displaySeq = displaySeq;
   }

   @Column(name = "CREATED_BY", nullable = false, length = 100)
   public String getCreatedBy() {
      return this.createdBy;
   }

   @Column(name = "UPDATED_BY", nullable = false, length = 100)
   public String getUpdatedBy() {
      return this.updatedBy;
   }

   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "CREATED_DATE", nullable = false)
   public Date getCreatedDate() {
      return this.createdDate;
   }

   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "UPDATED_DATE", nullable = false)
   public Date getUpdatedDate() {
      return this.updatedDate;
   }

   /**
    * @return the attributeValueProcessStatus
    */
   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "ATTR_VALUE_PROCESS_STATUS_CD")
   public AttributeValueProcessStatus getAttributeValueProcessStatus() {
      return attributeValueProcessStatus;
   }
   
   /**
    * @param attributeValueProcessStatus the attributeValueProcessStatus to set
    */
   public void setAttributeValueProcessStatus(AttributeValueProcessStatus attributeValueProcessStatus) {
      this.attributeValueProcessStatus = attributeValueProcessStatus;
   }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CarAttribute other = (CarAttribute) obj;
        if (this.attribute != other.attribute && (this.attribute == null || !this.attribute.equals(other.attribute))) {
            return false;
        }
        if ((this.attrValue == null) ? (other.attrValue != null) : !this.attrValue.equals(other.attrValue)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 37 * hash + (this.attribute != null ? this.attribute.hashCode() : 0);
        hash = 37 * hash + (this.attrValue != null ? this.attrValue.hashCode() : 0);
        return hash;
    }

       





}


Top
 Profile  
 
 Post subject: Re: Exception: Could not synchronize database state with session
PostPosted: Mon Dec 27, 2010 5:53 pm 
Newbie

Joined: Tue Dec 14, 2010 11:31 am
Posts: 4
OK, Finally I solved the issue.
And I got one more lesson about hibernate random behavior. I modified my code according to that and now its working on both QA and Prod.


Top
 Profile  
 
 Post subject: Re: Exception: Could not synchronize database state with session
PostPosted: Fri Apr 12, 2013 7:19 am 
Newbie

Joined: Fri Apr 12, 2013 7:15 am
Posts: 1
Hi,

Good to know that you have solved this issue, please do share how did you solve this.

I am facing same issue and tired of all possible settings n googling.

Thanks in advance.

Please share asap, this is SEV 1 going on in PROD.


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