| Author |
Difference between Read Lock and Write Lock
|
Amandeep Singh
Ranch Hand
Joined: Jul 17, 2008
Posts: 837
|
|
i understand that, if you use LockModeType.READ, then your application acquires a READ lock on an entity. Then neither of issues as Dirty Read or Phantom Read will take place. Whereas for LockModeType.Write, no update or delete operation is allowed on the entity. Suppose, 1) the persistence provider acquires a LockModeType.Read, then does it allows update or delete operation. If not, so what is the difference between LockModeType.Read and LockModeType.Write. 2) the persistence provider acquires a LockModeType.Write, then does it allows Dirty Read or Phantom Read. If not, so what is the difference between LockModeType.Read and LockModeType.Write.
|
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
|
 |
Chaminda Amarasinghe
Ranch Hand
Joined: May 17, 2006
Posts: 402
|
|
Originally posted by Amandeep Singh: i understand that, if you use LockModeType.READ, then your application acquires a READ lock on an entity. Then neither of issues as Dirty Read or Phantom Read will take place. Whereas for LockModeType.Write, no update or delete operation is allowed on the entity. Suppose, 1) the persistence provider acquires a LockModeType.Read, then does it allows update or delete operation. If not, so what is the difference between LockModeType.Read and LockModeType.Write.
to perform a update or delete, first you should have a read access. since the record is already read lock you(other transaction) cant update or delete the record
2) the persistence provider acquires a LockModeType.Write, then does it allows Dirty Read or Phantom Read. If not, so what is the difference between LockModeType.Read and LockModeType.Write.
this is correct
|
 |
Amar Gadewar
Greenhorn
Joined: Nov 25, 2008
Posts: 3
|
|
public void lock (Object entity, LockModeType mode);
This method locks the given entity using the named mode. The
javax.persistence.LockModeType enum defines two modes:
READ: Other transactions may concurrently read the object, but cannot
concurrently update it.
WRITE: Other transactions cannot concurrently read or write the object. When a
transaction is committed that holds WRITE locks on any entites, those entites will
have their version incremented even if the entities themselves did not change in the
transaction.
From Mastering EJB 3.0 :-
Read Locks are nonexclusive, in that any number of concurrent transactions can acquire a read lock. In comparison, write locks are exclusive - only one transaction can hold a write lock at any time.
|
 |
 |
|
|
subject: Difference between Read Lock and Write Lock
|
|
|