• 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

what are the semantics of PESSISMISTIC_READ AND PESSISTIMIC_WRIE

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from the java doc it says "A lock with LockModeType.PESSIMISTIC_WRITE can be obtained on an entity instance to force serialization among transactions attempting to update the entity data. " WTH does that MEAN? among who's transactions? does it refer to an object moving between session when one transaction is closed and then other is opened? another source refers to it as a lock when the object is updated, meaning what? when i'm using a setter? persist ? flush? is PESSIMISTIC_WRITE a more relaxed version between the classic pessimistic read and the optimistic lock?

from what i understand PESSIMISTIC_READ is the "classic" pessimistic lock where the record is locked using a for update statement, but, both use for update, so i'm assuming you can't really use both locks with different users, so what's left is the combination PESSIMISTIC_WRITE, and a regular optimistic locking, and what are the implications of using it over READ version?
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See, http://en.wikibooks.org/wiki/Java_Persistence/Locking#JPA_2.0_Locking

According to the Spec PESSISMISTIC_READ only blocks PESSISTIMIC_WRITE locks, not other PESSISMISTIC_READ locks.

In practice the difference between PESSISMISTIC_READ AND PESSISTIMIC_WRITE depends on the database and the JPA provider. I believe that most just use FOR UPDATE for both options and they are treated as the same (so PESSISMISTIC_READ will block other PESSISMISTIC_READ locks).
 
Greenhorn
Posts: 4
IntelliJ IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In computer science, serializing means turn data into a stream.

However, in English it can also be used to state "one after the other".
You don't want multiple writes to happen at the same time, but you do want them to happen one after the other ==> hence you want to serialize them.

However, that still doesn't answer some questions, their phrasing is not ideal.
To keep things simple, I understand it works as follows:

You can have many readers at the same time.
When there are readers, you can't have writers.
Once there are no more readers, a write can get the lock.
Only one writer can have the lock at any given moment.

This answers all scenarios. Let me know if there's something else I can help you with.
 
Attractive, successful people love this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic