Our Java EE web application performs database operations using iBatis (ORM). The database operation flow is as below
Flow : JSP --->Action--->ServiceIMpl--->DaoImpl---->Calling update query thru' IBatis
Note: The Action, Service & DAO classes are instantiated using Spring 2.5's Dependency Injection technique. We use Struts2.
Problem: 2 concurrent users search for the same record and User1 updates Attribute1 while User2 updates Attribute2. User1 first clicks on 'Save' and then User2 clicks on save (they follow each other with a difference of few seconds). When we see the data in database, only the User1's update is present. The Audit columns also show only the User1's update. The User2's update on Attribute2 is not done , at the sametime, no Exceptions are thrown.
We tried using the begin transaction and commit transaction in iBatis surrounding the invokation of the update query defined in the sqlmap xml. The same issue persists. We also tried removing those transaction commands, yet the problem persists.
Should we do anything special/different to handle concurrency during updates ? Wouldn't ORMs like iBatis handle by themselves ?
Additional Info: Further investigation revealed the following information.
When User1 & User2 clicks on the a record, it's complete data is fetched for viewing.
Now when both User1 & User2 changes few attributes and click save (concurrently), say first User1's data is updated and then while User2's data is being updated, the already updated data of User1 is over-written & lost.
What approach is usually followed in such screens to handle such scenarios ?