Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] (Newbie)Optimistic Locking for Web Apps

Hi

Could someone explain or point to a tutorial on how to implement optimistic
locking correctly in a web-application. I've added the version column and
annotation to my entity and I can see the version number incrementing in the
database every time I perform an update. I've read the article at
http://java.dzone.com/articles/dont-break-optimistic-locking but I can still
overwrite changes.

The logic goes basically - Client A wants to update an entity. The web-app
opens the entity manager, gets the entity, closes the entity manager so the
entities are now detached and displays the entity to Client A in an HTML
form. When client A submits the form, the web-app creates a new instance of
the entity, opens the entity manager, merges the new entity and closes the
entity manager again. At this point I see the version number increment in
the database. However, if while Client A is thinking about changing the
entity, client B selects the same entity, displays and submits his changes,
they're being overwritten when client A submits their changes - I'm not
getting an OptimisticLockingException being thrown and I see the version
number increment by 2.

Since the entity manager is closed between getting and updating the entity,
is it even possible to expect EclipseLink to deal with this? 
-- 
View this message in context: http://www.nabble.com/%28Newbie%29Optimistic-Locking-for-Web-Apps-tp25381983p25381983.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top