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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:55:32+00:00 2026-05-26T18:55:32+00:00

I am going through lock method of hibernate. I did not get what we

  • 0

I am going through lock method of hibernate. I did not get what we are trying to achieve through this method.

 p1  = (Person)session. get(Person.class,1);// person name is scott here
// here peson name got update to henry by anothet thread
session. lock(person, LockMode.READ) line 3
// still name is henry too

I tried above code snippet but it did not read the person from database at line 3.
Documentation says that This may be used to perform a version check.

Not sure how does it check version and helps the developer in any scenario?

Similarly not sure what session.lock(person, LockMode.None) will achieve. Documentation says LockMode.NONE is used to to simply re-associate a transient instance with a session.

Not sure what does it mean by reassociating a transient instance with session. A brief scenario will be a great help?

  • 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-26T18:55:33+00:00Added an answer on May 26, 2026 at 6:55 pm

    The different lock-modes are meant for preventing the entity from being modified and read from multiple sources simultaneously, see the documentation entry about pessimistic locking for details. In my experience, these are rarely needed, as the database isolation level usually takes care of locking as needed:

    It is not intended that users spend much time worrying about locking
    strategies. It is usually enough to specify an isolation level for the
    JDBC connections and then simply let the database do all the work.
    However, advanced users may wish to obtain exclusive pessimistic locks
    or re-obtain locks at the start of a new transaction.

    As for the “reassociating a transient instance with the session” (I actually think they mean detached instance?), consider the following picture (Hibernate entity lifecycle):

    Hibernate entity lifecycle

    This is the description from Hibernate community documentation:

    Hibernate defines and supports the following object states:

    • Transient – an object is transient if it has just been instantiated
      using the new operator, and it is not associated with a Hibernate
      Session. It has no persistent representation in the database and no
      identifier value has been assigned. Transient instances will be
      destroyed by the garbage collector if the application does not hold a
      reference anymore. Use the Hibernate Session to make an object
      persistent (and let Hibernate take care of the SQL statements that
      need to be executed for this transition).
    • Persistent – a persistent
      instance has a representation in the database and an identifier value.
      It might just have been saved or loaded, however, it is by definition
      in the scope of a Session. Hibernate will detect any changes made to
      an object in persistent state and synchronize the state with the
      database when the unit of work completes. Developers do not execute
      manual UPDATE statements, or DELETE statements when an object should
      be made transient.
    • Detached – a detached instance is an object that
      has been persistent, but its Session has been closed. The reference to
      the object is still valid, of course, and the detached instance might
      even be modified in this state. A detached instance can be reattached
      to a new Session at a later point in time, making it (and all the
      modifications) persistent again. This feature enables a programming
      model for long running units of work that require user think-time. We
      call them application transactions, i.e., a unit of work from the
      point of view of the user.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Going through K&R, I'm trying to get my head around C. I want to
Going through this article class ThreadTest { static void Main() { Thread t =
While going through some tutorials, I have encountered lines such as this: ((IDisposable)foo).Dispose(); Ignore
Going through my code, I was hoping to remove instances where I do this:
Im going through the beginning Django ecommerce book, and I am stuck on trying
Going through this tutorial https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC it is mentioned that to set up a call
Going through happstack-lite tutorial : we build functions that have return type of ServerPart
Going through some of my older Delphi projects and upgrading them to D2009, as
Going through Javascript documentation, I found the following two functions on a Javascript object
Going through the microsoft authentication tutorial listed here they have you create a master

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.