Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8601427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:50:23+00:00 2026-06-12T01:50:23+00:00

Our Java EE web application performs database operations using iBatis (ORM). The database operation

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:50:24+00:00Added an answer on June 12, 2026 at 1:50 am

    Your problem is not with transactions, it is that before you modify something you must be sure that no one has modified since you last read it.

    In web applications you should use optimistic locking. Basically, you have a “version” field in your table, that has an initial value at insert (tipically 1), and gets incremented with each update. The procedure is:

    1. Read data from the table, including the version field

    2. Send data the client side, including the version field

    3. Receive modified data from the client, including the version field unchanged

    4. Update the table and increment the version, but only if the version field in the row is the same as the original one received from the client. That is, where you had

      update
      ... 
      where id = :id_from_client
      

      , now you should do

      update 
      ..., 
      version = version + 1 
      where 
      id = :id_from_client and 
      version = :version_from_client
      
    5. Get number of updated rows (you can usually get this information right from the update operation of your persistence framework). If number of updated rows is 1, the operation succeded. If number of updated rows is 0, you should signal a concurrency error.

    An example:

    1. User1 get the data, with version = 17

    2. User2 get the data, with version = 17

    3. User1 atomically (atomicity comes from being a single SQL statement):

      • Check if version = 17
      • Updates the data
      • Sets version to 18

    4. User2 atomically:

      • Check if version = 17
      • As version was really 18, signals a concurrency error and aborts the operation, informing the user that the operation could not be completed due to somebody else modifying the same data.

    Most current persistence frameworks have support for this out of the box and mostly automatically (see JPA @Version annotation, for example). iBatis seems not to have it, but as it is very close to SQL, you should not have many problems implementing it yourself. See this blog entry for some details about optimistic locking with iBatis.

    With this scheme, you will not get lost updates, the only problem is that some specific cases will annoy the users a lot: imagine you spend 5 minutes completing some form only to be told at the very end that your operation could not be completed and you need to retry from the start!! In these few cases, you should implement something more sophisticated on top of optimistic locking. I would use some sort of remote resource leasing (links??):

    1. The client requests a lease for the data to the server.

    2. If the data is already leased to another client, signal a concurrency error.

    3. Else grant the lease to the client for a finite amount of time.

    4. Before lease expiration, the server grants the client exclusive access to the data. The client can also request a lease renewal (via AJAX, for example). The server can accept or deny the renewal. (Lease times and renewal policies should be decided by the server depending on the specific use case that is being dealt with).

    5. The lease expires (this can be done with a scheduled task at the server, for example). When the lease expires, the data should be considered “unlocked”, and the server should deny access to the client unless the client is granted a new lease.

    This way, your users can be informed that someone is modifying the same data before they even start whatever lengthy operation they were trying to complete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using the Display tag library in our Java based web application. Apart
We use Tomcat for our java web application. There is a properties file under
For our Kunagi Java web application we have a signed kunagi.jar file which contains
We have a Java web service that we call from our application. When we
I need to centralize all settings for our Java web application in one .properties
I have a Java web application leveraging JPA. The database instance is specified in
I am using a Java Web Service which is developed by one of our
We have an ASMX web service which we invoke from our ASP.NET application using
We are using OpenSessionInViewFilter in our JSF 1.1 web application which is using Spring
I have a Java web application connecting to an Oracle database running on another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.