File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes How to prevent concurrency issue in UPDATE via iBatis ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to prevent concurrency issue in UPDATE via iBatis ?" Watch "How to prevent concurrency issue in UPDATE via iBatis ?" New topic

How to prevent concurrency issue in UPDATE via iBatis ?

Senthil B Kumar
Ranch Hand

Joined: Feb 09, 2004
Posts: 160
Our J2EE 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 ?

Wouldn't the iBatis ORM handle the concurrency when 2 users are trying to concurrently update the same record ? Should we have to be setting the ISOLATION levels or moving such simple DML statements to stored procedures for the sake of concurrency ?

Note: We have also tried using the transaction APIs available in iBatis (as in the below example), but still the concurrency problem persists.

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 ?

Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside Here WEBlog
Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1101

Moving this post to the ORM forum where these questions are better answered.

I agree. Here's the link:
subject: How to prevent concurrency issue in UPDATE via iBatis ?
It's not a secret anymore!