Hello everyone,
I am facing problem while implementing Concurrency Control through Hibernate version tag. I will be not able to put code here due to some policies, but I will try to explain the problem.
We are using MVC architecture. So when page is displayed, we sent the version number with other fields to html page. E.g. version = 1 when User A has opened it. Same way, User B opened the same page and version =1 is stored as hidden field.
After that, User A saved the data and version number is increased to 2 in respective column of table and the same version is again sent back to page. When User B saved the date with version 1, it saves the data without throwing Hibernate Optimistic Locking Exception.
All hibernate related settings are in place. I was trying few things and was able to get exception when trying save new domain object. Let me explain more here.... I had tried to UPDATE my object two ways from Business/Service Layer. I have 30 columns in my table and I only need to save 5 columns from this page and other columns from other pages. Transaction is applied on all BO methods through Spring AOP.
1. Got Transfer Object (TO) from Controller. Got Latest Domain Object from DAO. Populate 5 updated columns and version in Domain Object.
This didn't throw any Exception while updating if the version is different in domain object and in database.
2. Got Transfer Object (TO) from Controller. Got Latest Domain Object from DAO. Created New Domain Object using Constructor. Populated 5 updated fields and version in new Domain Object from Transfer Object. Rest of the fields copied from latest domain object retrieved from Database.
This throws the Hibernate Locking Exception.
I am updating the version property of Domain Object in both the cases, but in 1st case, it is not throwing an exception. While in second case, it throws the exception.
Could you please throw some light on this?
I am using HibernateDaoSupport and HibernateTransactionManager of Spring.
Thanks in advance.
Regards, Nilesh Kamani
|