java - locking a object using hiberante session.load -


Hibernate is a PESSIMISTIC locking mechanism that can be used to lock the DB row.

session.lock (object object, locomod lockcode).

Let's say I lock an object:

  1) session.lock (myObject.LockMODE.READ) 2) session.lock (myObject, LockModa. Upgrade) 3) session Lock (myObject.LockMODE.UPGRADE_NOWAIT)   
  1. If any other thread raises the issue of Statement 1 above, what will it work for? Will this thread just block? Or will it be an exception? Something like CantAtyearlock exception? I want to understand the behavior of 1,2,3
  2. What if a thread gets a lock and then dies? Is the lock automatic? Or is the record closed forever? / P>

      session.lock (myObject, LOCKMODE.SOME_LOCK_MODE) // Death of Thread (say that JVM has died)     < / Div> 

    The lock is bound to the transaction once the transaction is committed or it is issued when rolled back. If your thread dies and your transaction hangs up, the lock still keeps.

    Other threads trying to get locked will just wait.

    If I remember correctly, call the call lock () results in a ... for update SQL statement.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -