In an enterprise application we have used pessimistic locking in some of the entity retrieval and persistence to avoid dirty reads and writes due to the extreme concurrent access. As we know, JPA provide both PESSIMISTIC_READ and PESSIMISTIC_WRITE capabilities which use shared lock and exclusive lock respectively.
If you make the sql query enabled with persistence settings, you can see the underlying queries of both lock types are going to be the same which make use of oracle's FOR UPDATE clause with the respective select queries. When browse through the articles on this, I found that it is allowed for the JPA provider to provide the PESSIMISTIC_WRITE, even the PESSIMISTIC_READ mode explicitly set in the queries. But it is not permitted the other way around.
Below article, provides a good insight into the pessimistic locking with different database providers.
https://vladmihalcea.com/2015/02/24/hibernate-locking-patterns-how-do-pessimistic_read-and-pessimistic_write-work/
ReplyDeleteThis blog is so nice to me. I will keep on coming here again and again. Visit my link as well.
Hibernate Training in Chennai
Spring Hibernate Training
Hibernate Training in Velachery
Spring Training in Chennai
Spring framework Training
soft skills training in chennai
core java training in chennai
Hibernate Training in Adyar