Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to prevent concurrency issue in UPDATE via iBatis ?

Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
Posts: 1104
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this post to the ORM forum where these questions are better answered.
grapes are vegan food pellets. Eat this tiny ad:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic