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?
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).
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.