The Problem:
The Scenario is very simple, if we(A user) retrieve from the database some information and before doing an update ,another user(B user) modifies that table before us, Our modifications(A user modifications), will overwrite the B users changes.
Handling the problem: Pessimistic and Optimistic Concurrency
Pessimistic concurrency involves locking the data at the database when you read it. You essentially lock the database record and don’t allow anyone to touch it until you are done modifying and saving it back to the database. Here you have 100% assurance that nobody will modify the record while you have it checked out. Another person will have to wait until you have made your changes.
Optimistic concurrency means that you read the database record, but you don’t lock it. Anyone can read and modify the record at anytime and you will take your chances that the record is not modified by someone else before you have a chance to modify and save it. As a developer, the burden is on you to check for changes in the original data ( collisions ) and act accordingly based on any errors that may occur during the update.
Handling the problem with NHibernate and Gsf concurrency models:
Version control – Numeric
In this case every time that we do some update, the Version property value will
be incremented, if someone has an older version of the entity and wants to do an update
StaleObjectStateException will be thrown.
Version control – TimeStamp
This case is basically the same but using a TimeStamp instead of an integers, is a little bit less secure
but some legacy applications still using this approach and we can reuse the Db.
You can do a quick test in order to see how it works, in this case we are using the TimeStamp Case:
Really hope this could help you.
the GenWise Team


