• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between Read Lock and Write Lock

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic