JPA Pessimistic Locking or Serializable Transaction Isolation
843830Feb 9 2009 — edited Feb 12 2009Hi All,
I am looking for some advice on achieving mutual exclusion over objects using JPA. I am using MySQL with innodb (supports row level locking).
I would like to be able to make use of the row level locking in MySQL, but it seams that JPA only supports optimistic locking by default.
I am developing a desktop application that will be used by multiple users at the same time...
I'd like the application to allow any number of users to view records but only allow one user at a time to have a write lock on any one record.
Optimistic locking doesn't appeal very much at all as it may be difficult to merge changes and would likely annoy users if they had to re-enter data, rather it would be better if they know they could not make edits, or rather only one user at a time.
I have read the following: http://en.wikibooks.org/wiki/Java_Persistence/Locking
which gives a good explanation of options available. I am currently using Hibernate as my persistence provider though I would be willing to move to another if needed as I understand that toplink/eclipselink may support pessimistic locking. Also though it would be good if any one could tell me more about JPA and Serializable Transaction Isolation as this would work quite well from what I have read.
Any suggestions, comments, solutions are much appreciated.
Thanks
Paul