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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:15:41+00:00 2026-05-28T03:15:41+00:00

we are using hibernate with optimistic locking. All our entities have the @version annotation.

  • 0

we are using hibernate with optimistic locking.
All our entities have the @version annotation.

This works fine, if a user tries to save an object that is stale we get a stalestateexception.
In our case we would like to give the user a notification screen to discard his changes or overwrite the current values in the database.

This a common use case for stale state exceptions.
My question is related to this use case. What is the best strategy if the user decides to overwrite the current database row with his changes? I’ve gone through the hibernate reference guide and different websites but all that is mentioned there is the fact that you have to catch the stalestateexception yourself and then programmaticaly handle the overwrite of the data.
I’m wondering if hibernate has some utilities to simplify this strategy, simplest thing i can get up with if the user decides to overwrite with his data is retrieving the last version of the entity from the database then copying all changed fields to this object and then saving the changed object back to the database.
But i can’t stop wondering if there isn’t a more elegant solution.

  • 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-05-28T03:15:42+00:00Added an answer on May 28, 2026 at 3:15 am

    I don’t think Hibernate will attempt to help you with this because requirements in this area are likely to be very complex and bespoke.

    I am guessing that if a user were to save an object which has been simultaneously changed by another user you most likely won’t want to simply load the object and copy all of the changed fields and undo all the other users changes. What happens if both users changed the same field? You wmight want to present the two versions to the user and ask them to decide which version is correct. A bit like merging changes in a version control system.

    Also you might have UI level validation which links fields which could be violated if you simply merge two versions of the same entity in the back end and persist it.

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

Sidebar

Related Questions

I'm using hibernate, I have a user entity, however I want it to implement
I have an project using Hibernate. This has a class named Question . Each
We're using hibernate entitymanager to map our entities through JPA. And we are using
I am new to use optimistic locking mechanism - I am using hibernate (in
We are using Hibernate 3.1 with Spring MVC 2.0. Our problem occurs when data
I've been using Hibernate for years and never have a problem with it, but
We are using Hibernate as persistency layer and have complex object model. Without exposing
I have an entity mapped in NHibernate with optimistic concurrency control using a SQL
Using hibernate @Any mapping to map multiple entities in the same, I haven't be
We're using Hibernate to load objects that meet certain criteria. If the user decides

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.