Vaadin locking example

I have application where multiple users can edit a table connected to jpa container.

Lets use this scenario:

User A edits entity, modal window with form editor opens, entity gets locked
Other users want to edit
entity, but they get notification that it is edited and can open it read-only or can’t do anything with it to make it simpler
User A finishes editing, entity unlocks and is ready to edit for others

So far I implemented it by adding boolean field named ‘locked’ which is set to true in form when user starts to edit, and is set to false when user cliks on save or abort buttons. It works fine until user simply refreshes browser window and ‘locked’ field remains true and record is locked forever :stuck_out_tongue:

Is there any complete example of locking mechanism?
I’ve read about optimistic and pesimistic locking, but couldn’t find how to use it
I’ve set @version field in entities, what else should I make?
Any try {} on commit?

Thanks in advance, M.