Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8003193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:35:39+00:00 2026-06-04T16:35:39+00:00

In a Spring 3.1 MVC app with Hibernate 4.1, I am using: Declarative transaction

  • 0

In a Spring 3.1 MVC app with Hibernate 4.1, I am using:

  • Declarative transaction management
  • Session per request
  • Optimistic locking by adding the “version” property in the domain objects
  • Reattaching detached domain object using saveOrUpdate()

Domain object is sent as command object during a GET request in order to be updated by the user.

In order not to get the error “optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)”, i am including in each jsp page the “<form:hidden path="version"/>” and updates are working fine.

In order to further protect the app, i am trying to add to the controller the following:

@InitBinder
public void initBinder(WebDataBinder dataBinder, HttpServletRequest request) {
  if (request.getMethod().equals("POST")) {
   dataBinder.setDisallowedFields( new String[] {"version"});
  }
}

But when i do that, i am getting the error optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)”.

Can someone please explain if what i am trying to do is valid as an approach and what i am doing wrong?

I believe ideally, i should try to protect and the primary key and perhaps some fields of the domain object that are not modified by the specific jsp page.

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:35:40+00:00Added an answer on June 4, 2026 at 4:35 pm

    This does not look correct, you should not disallow binding of version field – if you disallow the binding of version field, then your command object will not have the version field that you originally retrieved for the object from the DB, and at the point of persisting the command object hibernate would assume that the row has already been modified by some other transaction(as the version in the db and the command object does not match up).

    You can try to protect the field(id, version) etc, only at the point of first save of the entity(when id and version are not expected to be present), but for an update the original id and version have to be present.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spring web app that uses Hibernate and Velocity. It's an MVC
I am using spring web mvc for my app's UI part.. By using following
I am using spring mvc and spring security. In my security-app-context.xml I have: <authentication-manager>
I am using Spring Web MVC as frontend on hibernate with transactions (all annotation
I have a Spring 3 MVC app sing Hibernate as ORM. All works fine.
I have a bunch of Hibernate mapped objects in my Spring MVC app. Default
I am planning to build web app in spring mvc , hibernate. i want
I´m using JPA Hibernate and Spring MVC. I haved implemented repository pattern. I get
I have a Spring MVC app where I am using a singleton bean that
I'm writing a Spring 3 MVC based web app, using JSPs for my view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.