java - what is the purpose of LockMode OPTIMISTIC? -
as per how optimistic locking in hibernate, need enable optimistic locking version element or version annotation in hibernate. clear till here.
i not sure purpose of lock mode optimistic ? in kind of scenario, developer should use ?
to understand why want optimistic locking, first need understand no locking , pessimistic locking mean. i'm no hibernate expert, i'll tell without focus on hibernate.
when 2 process/users update same object 1 updates last win. need find way prevent this. 1 way pessimistic locking. here, put lock on object @ moment load database "select update". until transaction commited or rolled back, nobody else can "select update" object. problem is: when load entity via hibernate, specify if want load read-only purpose or if want modify object.
so here comes optimistic locking. concept assumes optimistically go ok in cases. when 2 processes/users update same object, second 1 not win, exception on commit.
Comments
Post a Comment