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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:14:55+00:00 2026-06-06T04:14:55+00:00

I have a situation whereby a thread can retrieve an object from the db,

  • 0

I have a situation whereby a thread can retrieve an object from the db, and edit it and when flush it I get a StaleObjectStateException because in the meantime another thread has edited the same object (Im using optimistic locking). I can see why it is happening but I cannot change this behaviour.

So what I try to do is retrieve the object again from the db and reapply the changes on the latest version but I get another StaleObjectStateException as soon as I do the retrieval before I’ve even changed anything, why is this ?

try{
    songs = nextSongGroup.getSongs(session);
    modifySongs(songs);
    session.flush();
}
catch(StaleObjectStateException sobe){
     songs = nextSongGroup.getSongs(session);
     modifySongs(songs);
}
  • 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-06T04:14:56+00:00Added an answer on June 6, 2026 at 4:14 am

    If you got this exception it’s too late already. You need to throw away the session and get a new one. Any queries on the same session will result in the same exception.

    Theoretically calling em.clear(); and rerunning the same query might help. I have never tried this though.

    For me I usually present the user with an Oops page that has a retry button that runs his request again on a clean session.

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

Sidebar

Related Questions

i have situation like this: class IData { virtual void get() = 0; virtual
I have situation in which I read a record from a database. And if
I have situation where a user can manipulate a large set of data (presented
I am in a situation whereby I have two sites, one a sub-domain of
We are in a situation whereby we have 4 developers with a bit of
I have the following situation (mostly because I didn't really thought it through in
I have a situation whereby, i need to create buttons dynamically and i need
I have a situation whereby I need a way of loading an MKMapView with
I have a situation whereby an application we use has many databases used for
I have a situation whereby a company is providing me an xml file with

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.