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 9303265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:26:41+00:00 2026-06-18T23:26:41+00:00

I have a web application made with Tapestry5 (java webframework) and Hibernate. Now I’m

  • 0

I have a web application made with Tapestry5 (java webframework) and Hibernate. Now I’m trying to add optimistic locking. So I added a version attribute and the optimistic locking works, so that was easy and fast.

But as my web application works with “session-per-request” pattern, I’m not sure what’s the best way of making use of this optimistic locking.

What happens:

UserA opens page with form which is loaded with values from entityA (version 1).

UserB opens page with form which is loaded with values from entityA (version 1).

UserA changes some values and submits the form.
-> New request retrieves entityA (version 1) and commits changes (entityA is now version 2)

UserB changes some values and submits form.
-> New request retrieves entityA (version 2) and commits changes (entityA is now version 3)

What should happen

Changes of UserB should not be committed. But because of session-per-request pattern the time window where optimistic locking error of Hibernate can occure is reduced to the timespan of just from the new request after the submit to the commit, which is not the desired result.

Possible solutions

After some research I found the following:

  • Add a hidden field to the form with the entities version

I could use this value to set the version of the entity before the commit, but Hibernate documentation doesn’t recommend setting this value.
Also it only works if the entity is detached and reattached, because else the manually set version value is ignored by Hibernate.

Secondly I could use this version value to do a manual check if the version, when the form was rendered, is the same as the version of the entity loaded in the request on submit. Then throw a OptimisticLockingException myself if needed.

  • Put the detached entity into HttpSession, so I don’t have to load it again on submit

Conclusion

These methods work, but don’t seem very practical to me and easy to make errors on.
So I’m wondering how other people implement this problem.

  • 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-18T23:26:43+00:00Added an answer on June 18, 2026 at 11:26 pm

    I ended up implementing the following:

    • Add a hidden field to the form with the entities version
    • Use of form dto objects
    • Attaching these dto objects to the httpsession (conversational state across multiple requests)
    • Manual version check between dto and actual object
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a web application using Visual studio 2008. till now it was
i have made a web application using java pages with eclipse. But i have
I'm trying to add pages written with Tapestry5 to a web application written with
I have a web application made in java and uses tomcat which i am
I have my web application made using JSP, Servlets,Java and Tom cat running on
Now, I have a web application made using [html, asp.net, sql server,javascript & ajax].
I have a web application that is made with Java+Struts. There is a form
I have a web application made with Spring that runs on Tomcat. On the
I have to migrate a web application I made with ASP.NET MVC to a
I have made a web application to a company that provides users to input

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.