|Re: Locking and Version [message #759263 is a reply to message #759244]
||Mon, 28 November 2011 07:11
| Tom Eugelink
Registered: July 2009
Actually it is quite simple; Eclipselink per default uses optimistic locking, this means that it actually does not use any explicit locking. All that happens is that if a record is updated, the version on which this applies is specified.|
For example, suppose you have a record with version 5 and Eclipse link updates it:
UPDATE record SET somefield = somevalue, version = 6 WHERE somekey = anothervalue AND version = 5;
If one record is changed (Eclipselink check for that), all is fine. But if no record is updated, someone has already done an update (or delete) and in that case Eclipselink will throw an exception.
So Eclipselink does not do any explicit locking. Naturally this all happens in a transaction and the update will place a write lock during the transaction. But wheter that is a row, page or table level locking is configured in the database.
This behavior is pretty unrelated to transaction management. Transaction management configures how long a transaction is kept open (usually only during the request).
On 2011-11-28 03:37, popprem wrote:
> I need to clarify some of my doubts related to eclipselink locking.
> How can i configure eclipselink that a row level lock should be held rather than a table level? I'm using spring transactions and havn't touched any configurations related to locking in eclipselink, so it uses default locking (optimistic). Please correct me if i'm wrong here.
> I have added @Version column in my entity classes to support locking mechanism. Is this a good way or do i have to use the Locking API in code too like entityManager.lock or @Lock etc? Should i use these locks in code even when i have configured database transactions through spring? I'm confused with the usage of code level locking and declarative transaction management.
Powered by FUDForum
. Page generated in 0.02171 seconds