Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Difference between Read Lock and Write Lock

 
Ranch Hand
Posts: 856
  • 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.
 
Ranch Hand
Posts: 413
  • 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
 
Greenhorn
Posts: 3
  • 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.
 
Police line, do not cross. Well, this tiny ad can go through:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic