I am having problem in updating an object.
I am using a timestamp for versioning.
For the first time, the object gets updated. But on updating the same object for second time, i get org.hibernate.StaleObjectStateException.
I have checked that the timestamp in the object is getting updated after first update. no idea why it still gives the error...
Hibernate mapping for the object:
<hibernate-mapping package="combos.cust.partymgmt.bo">
<class name="Customer" table="CUSTOMERS">
<id name="id" access="field" >
<generator class="assigned"/>
</id>
<timestamp name="mostRecentlyUpdatedTS" column="UPDATED_TS" access ="field"/>
<property name="createdTS" column="CREATED_TS" update="false" access ="field"/>
<property name="createdBy" column="CREATED_BY" update="false"/>
<property name="mostRecentlyUpdatedBy" column="UPDATED_BY" />
<property name="vatNumber" column="VAT"/>
<property name="firstName" column="FIRSTNAME"/>
<property name="lastName" column="LASTNAME"/>
<property name="dob" column="DOB"/>
</class>
</hibernate-mapping>
Stack Trace:
Hibernate: update CUSTOMERS set UPDATED_TS=?, UPDATED_BY=?, VAT=?, FIRSTNAME=?, LASTNAME=?, DOB=? where id=? and UPDATED_TS=?
(def.AbstractFlushingEventListener 277 ) Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [combos.cust.partymgmt.bo.Customer#2c95a92e03cf98e80103cfb342470029]
at org.hibernate.persister.entity.BasicEntityPersister.check(BasicEntityPersister.java:1456)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1999)
at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1923)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2163)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:675)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:210)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:311)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:609)
at bos.persistence.dao.hibernate.HibernateDataAccessObject.saveOrUpdate(HibernateDataAccessObject.java:50)
Any idea why????
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: