Avoiding concurrency errors when updating a database through AJAX

What are some strategies for avoiding concurrency errors when updating a database through AJAX. That is, in cases where a given user could attempt to modify the same row in the database with simultaneous requests (say, that he updates one column with information with an AJAX call, then immediately submits a form that updates the same row), what are some good ways yo prevent the two updates from colliding? On the JavaScript side one might make the AJAX call synchronous, but I question whether that is the best way to do it. Has anyone else confronted this?

Well, since no one seems to have any ideas so far, I'll throw in my two cents worth.
I'm not too familiar with AJAX so my advice may be limited.
I suggest you do a google search on Optimistic concurrency database to get some ideas on how to handle it.
If your update/insert/delete query is thread safe, then even if the same user double clicks the button fast enough to immediately have another update to the same record, then the first update will complete before the second one is carried out. Therefore no harm is done since he is just updating the same record. Since a typical update/insert/delete takes only a few milliseconds (querying may take a lot more time), its not likely he can click the button that fast. (I assume your using connection pooling for speed).
The trouble comes up when two people call up data from the same record in different browsers. The first one updates/inserts/deletes the record. Now the other user is looking at old data. When he updates/inserts/deletes, there is a problem. One way to handle this is to keep a copy of all the fields from that record in each user's session scope when they first fetch it from the database (example: oldName). Then when you go to update some time later, to this:
sql= update person set name=newValue where personID=3344 and name=oldName
Note oldName is from session scope.
If name in the database has changed, the update will not occur and will return 0 records updated. If it didn't change, it will update.
Note your update function should not throw an exception if it cant update, it should return false. Return true if it worked.
Example: public boolean updateName(String name)
Similiarly, your insert should not throw an exception if the record already exists, it should return false meaning it cant insert.
Exaple: public bolean insertName(String name). Same thing with delete function.
If a record cant be updated due to someone else updating the record while the user was looking at data, return a message that it wasn't updated due to that problem. Then show the user the new value in the database ask him if he wants to overwrite the new change.
Note even if you show 100 records on the JSP, only update the ones that have changed and not all 100. This way, its not likely he has updated the same records someone else has altered. Less likely a colision compared to updating all 100.
If your updating/inserting/deleting more than 1 record (say, 3), then you should look into setting up a transaction in addition to all the above and rolling back all of them if one fails.
Reading the section on databases from http://www.javapractices.com/home/HomeAction.do may also help.

Similar Messages

  • Preventing concurrency errors when updating a database with AJAX

    Here is a question that has arisen on my current project. What are some strategies for avoiding concurrency errors in cases where a given user could attempt to modify the same row in the database with simultaneous requests (say, that he updates one column with information with an AJAX call, then immediately submits a form that updates the same row)? In which layer(s) would this best be handled? Is the best alternative to make the AJAX updates synchronous, rather than asynchronous?

    pford68 wrote:
    Here is a question that has arisen on my current project. What are some strategies for avoiding concurrency errors in cases where a given user could attempt to modify the same row in the database with simultaneous requests (say, that he updates one column with information with an AJAX call, then immediately submits a form that updates the same row)? In which layer(s) would this best be handled? Is the best alternative to make the AJAX updates synchronous, rather than asynchronous?The database and database driver should handle that situation.

  • Error when Update Oracle database statistics

    HI All,
    Just recent we have upgraded oracle 11 in SAP Landscape. while we are trying to update database statistics through this command
    brconnect -c -u / -f stats -t all -f collect -p 4
    It is throwing following message without completion
    BR0280I BRCONNECT thread 2: time stamp: 2011-09-22 03.17.46
    BR0881I Collecting statistics for table SAPSR3./BEV3/CHASTEU with method/sample
    C ...
    ORA-24550: signal received: Unhandled exception: Code=ebf00baa Flags=0
    Can anyone guide us.
    Thanks.
    PrinceJ

    Have you applied patches to your 11g database?... Theres some info online about ORA-24550 been a know issue and a patch has been released for that...
    Regards
    Juan

  • Error when update "locate" database

    I'm running a Lion system (10.7.3) that was upgraded from Snow Leopard. I want to update the "locate" database. I tried what is prescribed everywehre I've searched on line:
    sudo /usr/libexec/locate.updatedb
    That gives errors:
    shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
    shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
    shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
    find: .: Permission denied
    What's wrong and how does one fix this?
    Note that now, whenever I try to use locate, I get no output; before I ran the locate.updatedb command, locate had been working as expected.

    What was suggested above didn't work for me.. typing "sudo" just gives me the help content, while "su" tells me "su: Sorry". Conversely "su -MYUSER" worked.
    However, this single command DID work for me (clearly, I am an admin user):
    sudo -u MYUSER /usr/libexec/locate.updatedb
    OSX: 10.8.3, Build 12D78 (semi-fresh OSX install)

  • HT5654 when updating my ipad through itunes, it said it needed to be restored. upon trying that, now it says.. cannot be restored. and brings up an error code

    when updating my ipad through itunes, it told me it needed to be restored, when i tried that, it then told me it cannot be restored, gave an error code, and all it does is sit at tell me to plug it in to itunes... which it is.. any ideas?

    Hello wombat98,
    Thank you for using Apple Support Communities.
    For more information, take a look at:
    Resolve iOS update and restore errors in iTunes
    http://support.apple.com/kb/ts1275
    If you can't update or restore your iOS device
    http://support.apple.com/kb/ht1808
    Have a nice day,
    Mario

  • Error when updating Playbook OS version via Blackberry Desktop Manager

    Greeting,
    I have a batch of old playbooks which having the stack charging issue, but I found that I can update the OS to the newest version (2.1.0.1917) via Blackberry Desktop Manager, then the charging algorithm will be changed to the updated one and go over this dead battery issue. I was able to do so successfully in the past week smoothly on several devices.
    But since this Monday, the Desktop Manager is saying "An updated Blackberry Desktop Software component must be installed before you can continue" when downloading the Desktop software and will appear "There was an error updating your software, an error has occurred while downloading the Blackberry Desktop Software.Please try again." and preventing the process. Seems there are some change on the server side starting this week which has caused this problem, but there's no error code to locate the exact issue.
    I tried on 2 different computers as well as completed uninstalling and re-installing the Desktop manager, also tried to disable the automatic update as been advised in some threads. So no clue how to deal with it for now. It will be highly appreciate if some one can share some idea.
    I've attached the step by step screenshots for reference, where you can find here:
    http://forums.crackberry.com/blackberry-playbook-f222/error-when-updating-playbook-os-version-via-bl...
    Thanks,

    BLock wrote:
    Sorry I can not help you with your problem but perhaps you can help me.  
    Can you advise where I can find info on "disable the automatic update"?
    just ignore the update if you dont want it on the playbook
    for reloading the OS
    First I would like you to do a Back Up of your PlayBook using your computer and BlackBerry Desktop Software.
    This can be downloaded for free from http://us.blackberry.com/apps-software/desktop/
    After the Back Up is complete I need you to unplug your PlayBook and then push and hold down the Power Button until the unit Force Powers Off.
    Now, while Desktop Software is still open on your computer and the PlayBook Powered Off, Connect the PlayBook to your computer.
    You should see and error screen from Desktop Software pop up that has the options to Retry, Update, or Cancel.
    QUICKLY choose the Update option.
    This will erase all the information off of your PlayBook and Re-Write the Software back onto it. Once it's complete your PlayBook will need to go back through the setup wizard, and you can then perform a restore using Desktop Software to return your information. The only thing that won't come back after the restore are the apps that you downloaded from App World but they can be easily Re-Installed using the My World feature in App World.
    Click here to Backup the data on your BlackBerry Device! It's important, and FREE!
    Click "Accept as Solution" if your problem is solved. To give thanks, click thumbs up
    Click to search the Knowledge Base at BTSC and click to Read The Fabulous Manuals
    BESAdmin's, please make a signature with your BES environment info.
    SIM Free BlackBerry Unlocking FAQ
    Follow me on Twitter @knottyrope
    Want to thank me? Buy my KnottyRope App here
    BES 12 and BES 5.0.4 with Exchange 2010 and SQL 2012 Hyper V

  • Error when updating! Help please!!

    I've been having a problem with the artwork updating on my 5th iPod. I kept getting an error when updating in iTunes whenever I added artwork to songs. So I was told to go into iTunes and go under iPod options and UNCHECK the box to display the artwork on my iPod. Then click okay. Then, go back into it and CHECK the box TO display the artwork and I get an error; "..Unknown Error occurred (-50)". Same error. And yes I have pressed the center button on my iPod to scroll through the different things. And I have restarted the program and computer. Tried disconnecting hte iPod, closing the program, restarting computer, restarting iTunes and reconnecting iPod and every combination of the steps (I've done many searches on this subject here) and same result. I've tried other different things but it all ends up to this error. Can some one please help me
      Windows XP Pro  

    Hi Melophage,
    I managed to do a OS X Recovery Reboot by restarting my computer and holding down Command and 'R'. I reinstalled OS X, and now my computer is working again.
    However I'm going to take my computer into the Genius bar for review.
    I have a Macbook Pro from 2012 (with a 2.6 GHz Intel Core i7 Processor) and was attempting to update OS X (I think Version 10.8.5).
    Many thanks for your message.

  • Error when updating HANA Live Authorization Assistant

    Hi Guys,
    I'm trying to use the HANA Live AAA component for the creation of HANA Roles and it works fine when trying to generate the roles but it throwing me an error when updating them. The error happens at the beginning when the plugin attempts to load the Users from ECC. The message is:
    SAP DBTech JDBC: [1300]: fetch returns more than requested number of rows: [1300] "_SYS_BIC"."sap.hba.tools.auth.db/GetUsers": line 20 col 1 (at pos 1770): [1300] (range 3) fetch returns more than requested number of rows exception
    Anyone has gone through this error before??
    Thanks!
    Cheers.

    Ok Guys. No answer to this just yet.
    We decided not to use the tool and build our security with HANA security functionalities. It takes a bit longer but It's more robust in the long run in terms of maintenance.
    Cheers.
    Christian.

  • RPLDAP_EXTRACT - Error when updating the LDAP directory

    I am connecting SAP IdM 7.0 to SAP HCM via VDS.
    So far:
    The VDS responds to LDAP browser, the connection tests from SAP GUI are succesful.
    I can execute my copy of the standard report LDAPEXTRACT46C in SAP GUI and can see what data is exported.
    I get the "Error when updating the LDAP directory" error when trying to execute the RPLDAP_EXTRACT program.
    An error occurred during creation of one or more data records in the LDAP directory. The error has been logged in the system used to export data to the LDAP directory.
    You can find logs in the database tables TLDA_LOG (HR-LDAP: Non-Exported Data Records) and TLDA_MSG (Error Messages About Data in Table TLDA_LOG). Table TLDA_LOG contains data records that could not be exported; table TLDA_MSG contains the corresponding messages.
    I didn't see anything that makes sense in tables mentioned in the error message above.
    I have some questions as the documentation supplied with IdM is bit brief; According to the configuration guide I don't need to have any mapping in VDS like "conversion of internal attributes" or "conversion from internal attributes", has anyone else entered the mapping in VDS?
    Any pointers in going forward?
    Edited by: pasikuikka on Oct 20, 2009 11:01 AM

    Hi Pasikuikka,
    just a few questions:
    Have you checked TA HRLDAP_MAP? (Each field must have its expression in the LDAP-Target)
    Have you checked TA LDAPMAP? (Each field must have its expression in the LDAP-Target)
    Maybe there are attributes listed in the query, but not in the HCM-Staging-Area in the Identity Center.
    Have been new attributes created in the HCM-Staging-Area and, if so, are they connected to the right Entry-Type (MX_HCM_Employee or something like that)?
    Hope this puts you on the right track.
    Kind regards,
    Achim Heinekamp

  • Error when making a database call froman ejb

    Hello,
    I am getting the following error when accessing the database from an ejb -
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
         java.rmi.RemoteException
         at com.sun.corba.ee.internal.iiop.ShutdownUtilDelegate.mapSystemException(ShutdownUtilDelegate.java:68)
         at javax.rmi.CORBA.Util.mapSystemException(Util.java:65)
         at com.ejb._EULookupRemoteIF_Stub.fetchAllLookups(Unknown Source)
         at com.ejb._EULookupRemoteIF_Stub.fetchAllLookups(Unknown Source)
         at com.servlets.login.EUClsLoginServlet.doPost(Unknown Source)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:720)
         at org.apache.catalina.core.StandardWrapperValve.access$000(StandardWrapperValve.java:118)
         at org.apache.catalina.core.StandardWrapperValve$1.run(StandardWrapperValve.java:278)
         at java.security.AccessController.doPrivileged(Native Method)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:274)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
         at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:157)
         at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
    Caused by: java.rmi.RemoteException
         at com.sun.enterprise.iiop.POAProtocolMgr.mapException(POAProtocolMgr.java:451)
         at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:545)
         at com.ejb.EUClsLookupBean_EJBObjectImpl.fetchAllLookups(EUClsLookupBean_EJBObjectImpl.java:101)
         at com.ejb._EUClsLookupBean_EJBObjectImpl_Tie._invoke(Unknown Source)
         at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:569)
         at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:211)
         at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:113)
         at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:275)
         at com.sun.corba.ee.internal.iiop.LocalClientRequestImpl.invoke(LocalClientRequestImpl.java:96)
         at com.sun.corba.ee.internal.corba.ClientDelegate.invoke(ClientDelegate.java:237)
         at com.sun.corba.ee.internal.POA.GenericPOAClientSC.invoke(GenericPOAClientSC.java:97)
         at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:457)
         at com.ejb._EULookupRemoteIF_Stub.fetchAllLookups(Unknown Source)
         ... 16 more
    Any help?

    Please look in those 16 other stack traces for more details, there should be an actual SQLException if
    it's a database problem, and/or the actual bean method that caused the problem.
    Regards,
    Marina

  • Error Loading Hierarchy Error when updating Idocs in Source System

    Hello  Friends,
         I am loading  hierarchy data  using Info pac into  0FUNDS_CTR . I have selected  a hierarchy under hierarchy selections tab  in the Info pac .
    All Partner profiles in WE20 seems OK .   But When I loaded data , throwing errrr message  as below
    Error when updating Idocs in Source System
    Diagnosis
    Errors have been reported in Source System during IDoc update:
    System Response
    Some IDocs have error status.
    Procedure
    Check the IDocs in Source System . You do this using the extraction monitor.
    Error handling:
    How you resolve the errors depends on the error message you get.
    When I checked in TC WE05 says that  IDoc: 0000000000355113 Status: Error during syntax check of IDoc (outbound) with status 26 .
    Please advice .
    Many thanks

    Hi  Krishna4bi,
    Actually we will monitor idoc status in BD87 in SAP BI As well ECC , while extracting the data from source sytem  if any idoc struck we will manually process in BD87 , But you are telling that while loading the datasource the error occurred , so please check once in ECC side . Otherwise see how many packets are still process, make it red that infopackage and do manually update.
    Hope it helps,
    By,
    Praveen Yagnamurthy,
    SAP BI Consultant,
    Blue Marlin Systems-INDIA.
    http://bluemarlinsys.com/bi.

  • Error when updating Idocs in Source System - Urgent

    Hi Team,
    When i was loading the data from SAP R/3 to BW, i was facing the error "Error when updating Idocs in Source System" (0 From 0 Records).
    When i check in the Environment>Transaction RFC->In the Source System, it was displaying the error--
    <b>" Import container contains errors (are any obligato) in the Function Module: IDOC_ERROR_WORKFLOW_START_R".</b>
    Can any one please help me to solve this error.
    This is am Urgent requirement for me to deliver.
    Thanks & Best Regards,
    Venkata.

    Hello VenkaTa,
    How r u ?
    The workflow settings are not proper it seems. Ask the BASIS people to correct the Work Flow Settings. Then try Updating the IDOCs manually.
    Also check the Inbound and outbound IDOCs in the Source system. The outbound should contain some warnings or errors.
    Best Regards....
    Sankar Kumar
    +91 98403 47141

  • Error when updating Idocs in Source System

    Hi All,
    We did a recent copy from QAS to DEV,after which am unable to run my process chains ,the load status still showin yellow signal,whereas job is getting finished but am unable to load datas to the targets. Am getting the following error message when i see the display message in process chain.
    System Response
    Some IDocs have error status.
    Procedure
    Check the IDocs in Source System . You do this using the extraction monitor.
    Error handling:
    How you resolve the errors depends on the error message you get.
    Error when updating Idocs in Source System     
    Could anyone please let me know what can be done ?
    Thanks
    con

    Hello All,
    I have same problem but its RESOLVED by the following process.
    Step - 1
    execute  the Function module "SCP_LANGUAGES_IN_INSTANCE".  It may or maynot give some output. Just note if it give the output
    Step - 2
    in Transaction SE38 execute the program "RSCPINST".
    Just Click on the Activate button (dont select anything).
    Step - 3
    Again do the same thing specified in Step - 1.  Now it will give the output saying that Language is DE.
    So by the above procedure my issue is been resolved.
    Regards
    Sankar

  • Error when updating

    I get an error when updating. The message states,
    Adobe Photoshop Elements 12.1 update
    There was an error installing this update. Please quit and try again later. Error Code: U44M1I200
    Photoshop Camera Raw 8.5
    There was an error downloading this update. Please quit and try again later. Error Code: U43M1U49
    Do you know what causes this issue?

    Please see- https://helpx.adobe.com/photoshop-elements/kb/elements-12-1-update-error.html
    This error code occurs when multiple instances of Updater are open. Please refer to following forum link for more details: http://forums.adobe.com/message/4913117#4913117#4913117
    Thanks
    Andaleeb

  • 11gR2 Error when installing a database and schema

    I have install 11gR2 on my laptop with window 7 4gb ram 500gb hard drive
    I getting this error
    ORA-01503: CREATE Controlfile / Failed
    and
    ORA-01158: Database already mounted
    i need to set up a database a 3 different schema
    because i am doing a install of Hyperion Share service, Essbase and Planning
    Please advise

    Pl do not post duplicate threads - 11gR2 Error when installing a database essbase on install of 11.1.2.1
    Your original thread was moved to the Essbase forums since this is Essbase related
    Srini

Maybe you are looking for

  • Programm stürzt ab

    Beim Laden von RAW Dateien (je ca 30MB) in der Bibliothek stürzt L5 ab. Das hat angefangen seit ich Fotos mit Nikon D7100 mache, und eine 64GB SDXC Speicherkarte benutze. Die Fotos sind auf dem PC (geladen mit einen sdxc Lesegerät) und im Explorer vo

  • Random order for slide show?

    I have a lot of pictures in an album that I would like put in random order for a slide show. I want to burn that to a dvd to play at our day care centers (pics of the kids throughout the summer). is there any way to do this other than dragging and dr

  • Plug-in for Aperture conversion

    I just bought, mistakenly I think, Lightroom 5, which turns out to be version 5.2.  I read now that the plug-in for import of Aperture libraries comes with version 5.6.  I can't find any update; when I look for it, I just see it for Windows or CC.  H

  • Failed to initialize privileges when trying to boot a zone

    I just installed build 69 on a Sun Blade 1500. I tried setting up a zone called myzone using the following configuration zonepath: /export/myzone autoboot: false pool: inherit-pkg-dir: dir: /lib inherit-pkg-dir: dir: /platform inherit-pkg-dir: dir: /

  • Production order settlement info

    Hi, In production order settlement category  is MAT.Some times it is CTR .But costing varient is PPP2.In settlement configuration i check that Allocation structure is A1 ,PA transfer sture is A1 butdefault object trype  is blank . So how system take