Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Read Lock and Write Lock

 
Amandeep Singh
Ranch Hand
Posts: 850
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 404
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic