Tuesday, June 02, 2009

Optimistic Concurrency using Hibernate

I came across an interesting but most common use case last week. It goes like this that we need to manage concurrency for the data which are being worked on by multiple users at the same time…Obviously Pessimistic Locking of Database records is not a possible solution as it will affect the performance and scalability of the application.

When looking for a solution, straight away the answer could be that the Framework / ORM has to provide some mechanism to control.

Luckily the use case we are working on is using Hibernate and we ought to find a way from Hibernate. Being a strong recommender of hibernate I felt confident that it will have something to solve this.

Hibernate provides technique called "Optimistic Concurrency" using Versioning / Timestamp. What is intersting here? Versioning and Timestamp are same old stuff. But above these two it has another concept called "Session-Per-Conversation" or "Long Conversation" using which we can do Optimistic Concurrency control without change in datastructure and without much change in code.

For More details visit:
http://www.hibernate.org/hib_docs/reference/en/html_single/#transactions-optimistic
http://hibernate.bluemars.net/43.html

No comments:

Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory