vijayjanakiram wrote:
We are using NHibernate Version 1.2.0 and we have an issue related to concurrency. The scenario is as follows.
Our application is web application and we open the Nhibernate session at the business logic layer and perform insert or update of the entity there.
User A and User B opens a particular webpage and updates a particular entity at the same time which results in invalid state.
Is there an out of box option in NHibernate to avoid concurrency issue?
Thanks
See the NHibernate documentation:
http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#transactions
If this is considered an unlikely occurrence I would recommend using a version property on your object. Then it will only update your object if it has not been updated since this user loaded the object.
Now this may not be exactly what you are looking for if you just reload the object from the database just before saving. If the concurrency issue lives outside of the load/save cycle, then it really is more of an application issue, than an OR/M issue. All applications need to be written to take concurrency into account.