2

I am using hibernate, spring, struts framework for my application.

In my application, each of the table has one field called as Version for tracking updation of any records.

Whenever i am updating existing record of my Country table which has version 0, it works fine & update the record update the version field to 1.

But whenever i am trying to update that version 1 record, it gives me error as follows:

org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [com.sufalam.business.marketing.model.bean.Country] with identifier [3]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.company.business.marketing.model.bean.Country#3]

Is there any way to resolve it ?

0

3 Answers 3

3

The version column of Hibernate allows you to implement optimistic concurrency control.

Every time an object should be updated Hibernate checks if the version value stored in the database is the same as the version value in the object. If the two are different the StaleObjectStateException is thrown, meaning someone else has updated the object meanwhile the current session loaded, edited and stored it.

You have to make sure that the version value in your object is set to the correct value. Sometimes if you detach objects from the session and reattach them (merge) the value version column is not set correct (eg in web applications when values are retrieved from forms)

Sign up to request clarification or add additional context in comments.

Comments

0

"Row was updated or deleted by another transaction". Last time i received this I was doing things spread across more than one org.hibernate.Session object.

Comments

0

I don't remember exactly but are you supposed to hang on to the instance you saved? At least when usng JPA there is a return value from the merge method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.