Incorrect update

Hello
Oracle 11.1.0.6.0
We have a financial app developed in house using java and tomcat. Under very high load we have noticed some anomalies.
There are multiple customers and only one vendor. We see something like this
Vendor balance = 0
Customer 1 balance = 5
Customer 2 balance = 5
1) Customer 1 initiates transaction - opens cursor and inserts into customer table
2) Customer 2 initiates transaction. - opens cursor and inserts into customer table
3) Customer 1 updates customer balance (-1) and vendor balance (+1)
4) Customer 2 updates customer balance (-1) and vendor balance (+1)
5) Customer 1 commit
6) Customer 2 commit
Vendor Balance = 1
Customer 1 balance = 4
Customer 2 balance = 4
So Vendor Balance should be 2. Looks like when the update takes place the update statements must both be reading a value of 0. That is the updates are taking place at the SAME time?
The application developer is unhappy about this ;-)
I have suggested use of select for update to serialise the transactions.
This is felt to cause too much of an overhead as they are no longer concurrent. Which is the point....
Any thoughts or ideas ??
Regards
Ali
Code used
create or replace procedure doPaymentTransaction
( paymentResponseId IN VARCHAR2
) AS
cursor getPaymentDetails is
SELECT
req.customer_play_ref customerPlayRef
,req.order_description orderDescription
,req.vendor_id vendorId
,req.vendor_transaction_id vendorTransactionId
,req.price amount
,c.id customerId
,c.balance customerBalance
,v.balance vendorBalance
FROM
payment_response resp
,payment_request req
,customer c
,vendor v
where
resp.id = paymentResponseId
and
req.id = resp.payment_request_id
and
c.play_ref = req.customer_play_ref
and
v.id = req.vendor_id;
rec getPaymentDetails%ROWTYPE;
ctxId VARCHAR2(255);
vtxId VARCHAR2(255);
begin
OPEN getPaymentDetails;
FETCH getPaymentDetails INTO rec;
    select hibernate_sequence.nextval INTO ctxId FROM sys.dual;
    insert into customer_transaction (
        id
        , version
        , amount
        , customer_play_ref
        , date_created
        , transaction_description
        , description
        , new_balance
        , old_balance
        , payment_response_id
        , vendor_id
        , class
         values (
        ctxId
        , 0
        , rec.amount
        , rec.customerPlayRef
        , sysdate
        , rec.orderDescription
        , 'debit'
        , rec.customerBalance - rec.amount
        , rec.customerBalance
        , paymentResponseId
        , rec.vendorId
        ,'CustomerDebit');
    update customer
        set balance= balance - rec.amount
            ,version = version + 1
        where id=rec.customerId;
    insert into customer_customer_transaction
         customertx_idx
        ,customer_customertx_id
        , customer_transaction_id
    values
        hibernate_sequence.nextval
        , rec.customerId
        , ctxId
    select hibernate_sequence.nextval INTO vtxId FROM sys.dual;
    insert into vendor_transaction
    id
    , version
    , customer_play_ref
    , date_created
    , description
    , new_balance
    , old_balance
    , payment_response_id
    , vendor_id
    values (
    vtxId
    , 0
    , rec.customerPlayRef
    , sysdate
    , 'credit'
    , rec.vendorBalance + rec.amount
    , rec.vendorBalance
    , paymentResponseId
    , rec.vendorId
    insert into vendor_vendor_transaction
        vendortx_idx
        ,vendor_vendortx_id
        , vendor_transaction_id
    values
       hibernate_sequence.nextval
        ,rec.vendorId
        ,vtxId
    update vendor set
     balance= balance + rec.amount
    , version = version + 1
    where id=rec.vendorId;

Thank you - that is a very useful article. As a DBA i was aware of pessimistic v optimistic locking but was unaware of how to programmatically ensure concurrency with an optimisitic model.
Regards
Ali

Similar Messages

  • Special ledger Balance Field incorrectly updated after note 577644

    Hi gurus,
    We are extracting data from a custom SL datasource we are generated.
    Reading documentation, we realized we needed to implement note 577644 for populate balance properly to next periods, and we included the start routine referred in the note.
    Now, we are facing a very strange problem, when we upload requests to ODS, a very few documents are getting incorrectly updated. Balance field is getting a "0" when it has value in the period. Checking the modification log of the ODS for this records we see that there are 3 records per period generated for this documents at the same requests. Two of them with the correct values and another one with the "0".
    Moreover, if we extract this particular records individually, updated values are OK.
    PSA data, etc is OK, it seems it should be a bug of the start-routine proposed in note 577644.
    Has anyone encountered with  this bad behaviour??
    Thanks in advance.

    Problem resolved..
    Need to run transaction GVTR to transfer balances from previous years..

  • Errors while running BPEL and incorrect UPDATE statement

    Hi,
    I installed following software.
    1. Oracle Database 10g Release 2
    2. SOA Suite 10g Release 3
    3. Oracle JDeveloper (10.1.3.4)
    I developed a BPEL process to lock a userid in PeopleSoft.
    I have two issues.
    a) I am getting error as shown below
    b) its generating incorrect UPDATE statement, even though its assigning correct values in XML (UPDATE PSOPRDEFN SET LASTUPDOPRID = ?, OPRID = ? WHERE (ACCTLOCK = ?) i.e instead of setting OPRID in where clause its setting ACCTLOCK in where clause
    <messages><input><Invoke_1_update_InputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PsoprdefnCollection"><PsoprdefnCollection xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/top/UpdateUserProfile">
    <Psoprdefn>
    <oprid>snagulapalli</oprid>
    <version/>
    <oprdefndesc/>
    <emplid/>
    <emailid/>
    <oprclass/>
    <rowsecclass/>
    <operpswd/>
    <encrypted/>
    <symbolicid/>
    <languageCd/>
    <multilang/>
    <currencyCd/>
    <lastpswdchange/>
    <acctlock>1</acctlock>
    <prcsprflcls/>
    <defaultnavhp/>
    <failedlogins/>
    <expent/>
    <oprtype/>
    <useridalias/>
    <lastsignondttm/>
    <lastupddttm/>
    <lastupdoprid>Laptop BPEL</lastupdoprid>
    <ptallowswitchuser/>
    </Psoprdefn>
    </PsoprdefnCollection>
    </part></Invoke_1_update_InputVariable></input><fault><remoteFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="code"><code>17002</code>
    </part><part name="summary"><summary>file:/D:/product/10.1.3.1/OracleAS_1/bpel/domains/default/tmp/.bpel_Sandbox_9.0_882edce22e996c64b48ea25cbe023033.tmp/Update_User_Profile.wsdl Update_User_Profile_ptt::update(PsoprdefnCollection) - WSIF JCA Execute of operation 'update' failed due to: DBWriteInteractionSpec Execute Failed Exception.
    update failed. Descriptor name: http://UpdateUserProfile.Psoprdefn. Caused by: Io exception: Connection reset by peer: socket write error
    ; nested exception is:
    ORABPEL-11616
    DBWriteInteractionSpec Execute Failed Exception.
    update failed. Descriptor name: http://UpdateUserProfile.Psoprdefn. Caused by: Io exception: Connection reset by peer: socket write error
    Caused by Exception TOPLINK-4002 (Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Io exception: Connection reset by peer: socket write errorError Code: 17002
    Call:UPDATE PSOPRDEFN SET LASTUPDOPRID = ?, OPRID = ? WHERE (ACCTLOCK = ?)
    bind => Laptop BPEL, snagulapalli, 1
    Query:UpdateObjectQuery(<Psoprdefn 1 />).
    </summary>
    </part><part name="detail"><detail>
    Internal Exception: java.sql.SQLException: Io exception: Connection reset by peer: socket write errorError Code: 17002
    Call:UPDATE PSOPRDEFN SET LASTUPDOPRID = ?, OPRID = ? WHERE (ACCTLOCK = ?)
    bind => Laptop BPEL, snagulapalli, 1
    Query:UpdateObjectQuery(<Psoprdefn 1 />)</detail>
    </part></remoteFault></fault></messages>
    Regards,
    Shanti Nagulapalli.

    What version of SOA Suite are you using, SOA Suite 10g Release 3 is not enough information. Make sure that it is the same as your JDev version if it isn't then either downgrade the JDev or upgrade the SOA Suite.
    If you are still on SOA 10.1.3.1 then I would upgrade as there are many bugs in this release.
    These kind of strange errors are generally caused by incompatibility between design time (JDev) and run time (SOA Suite)
    cheers
    James

  • Ipod incorrect update from itunes

    I recently connected my 30GB Ipod Video to my laptop running Windows XP Pro. Once connected itunes said it needed an update once updated it doesn't work now. On the screen of the ipod whilst disconnecte4d it says to connect to itunes and reformat it. Also trying to access it through My computer when its in disk mode or normal mode it says it isn't formatted and asks if i want to e format it. I don't want to format it because there are files on iot that i would like to retrieve, is there anyway of retrieving these files? Also has anyone else had this problem?

    One major thing i forgot to mention was that itunes didn't recognise my ipod as a 5th gen and updated it for another ipod, thats why this topic was called incorrect update from itunes.

  • Incorrect Update Count by executing a stored procedure from Java

    Hi Guys,
    I am calling a stored procedure from the java program which is modifying the rows of a table. Now I want to know how many rows have been modified by executing the stored procedure. I am writing the following code for the purpose:
    OracleCallableStatement stmt =
    (oracle.jdbc.driver.OracleCallableStatement)con.prepareCall("{callsp_um_setForumID(?,?)}");
    stmt.setInt(1,101);
    stmt.setInt(2,666);
    n = stmt.executeUpdate();
    System.out.println(n + " row(s) updated");
    This procedure is actually modifying the table(When I query the databse it has modified 1 row). But it is returning a value 0 and is printing "0 row(s) updated".
    Is there a way by which I can find out the number of rows updated by executing the stored procedure?
    Thanks
    Sachin
    [email protected]

    I'm no expert on this, but I have a similar call where I fetch
    an Oracle REF CURSOR from a call to a stored function. If you
    fetch the cursor as an Object from your CallableStatement, you
    can then cast it to a ResultSet e.g.
    mystatement.executeUpdate();
    ResultSet rs = (ResultSet) mystatement.getObject(1);
    Then you should be able to loop through your ResultSet as usual.
    Good luck!
    Chris

  • Incorrect update SIS table for Product Allocation

    I have set up product allocation, use a custome table S501.
    S501 contains characteristics fields:
    KONOB: Product allocation object
    VKORG: Sales Org.
    VTWEG: Distribution Channel
    ZZREGION: Region (custom field)
    MATNR: Material code
    When I create and save a sales order,
    VKORG and VTWEG are updated as "***" and "*" in table S504.
    ZZREGION and MATNR are updated correctly.
    Could you please kindly advise how sales org. and dist. chan. can be copied to table S504 correctly? Thanks.

    If the challan has 2 or more line items & one of the line item is fully reconciled thats why it is showing the status F in item detail table & P in header table of challan

  • Incorrect Updates Listed in WSUS

    Running WSUS 3.2 Version
    While planning for Windows Patching , I selected required products/classification and synchronized updates. I did not select Microsoft Sharepoint and Exchange 2010/2013 but ALL Updates showing updates for Exchange as well as Sharepoint.
    Now, because of this, While approving all updates in WSUS, all these exchange/sharepoint patches got approved. To correct this, I then reapproved the patches for computer groups and selected Not Approved for all patches and computer groups.
    Now, I have set the deadlines again for all computer groups and manually had to decline Exchange/Sharepoint patches.
    COuld you please suggest if this is due to WSUS database corruption of something else.
    Thanks,
    MCSE Certified

    While approving all updates in WSUS
    Here's my first observation.... Did you really approve **ALL** of the updates?
    COuld you please suggest if this is due to WSUS database corruption of something else.
    I highly doubt that database corruption has anything at all to do with this situation.
    Lawrence Garvin, M.S., MCSA, MCITP:EA, MCDBA
    SolarWinds Head Geek
    Microsoft MVP - Software Packaging, Deployment & Servicing (2005-2014)
    My MVP Profile: http://mvp.microsoft.com/en-us/mvp/Lawrence%20R%20Garvin-32101
    http://www.solarwinds.com/gotmicrosoft
    The views expressed on this post are mine and do not necessarily reflect the views of SolarWinds.

  • Incorrect update in MD04

    Hi All,
    I am facing a problem where in i have deleted a delivery but it is still blocking the stock in MD04,it seems there is a OSS note for the same,If so please provide me the Note number if not can anyone help with the solution.
    Thanks in anticipation
    Regards
    Muzaffar

    if it doesnt answer my question as i had already mentioned
       in my question that delivery is deleted but it is still
        appearing in my stock requirement list(MD04).
    Please go through my above suggestion once again  which is the solution for your issue.  You have to assign Reason for Rejection in sale order and run the report cited above.
    thanks
    G. Lakshmipathi

  • HELP! Need to undo updates for a Goods Receipt - incorrect PO

    Hi there,
    I'm fairly new to SAP Business One and made a mistake with my last Purchase Order/Goods receipt.
    The parcel I had to book in arrived but the invoice had no PO number, so using the Query Manager I found out which Purchase Orders included the product codes. There were a few POs with the same products and I got confused which was which.
    When adding the new Goods Receipt I 'copied from' the wrong Purchase Order and saved the updates so now it appears that we have received some of the products from this order, which aren't due for another two months. They are highlighted in grey on the Purchase Order. If I 'copy from' this PO to create the Goods Receipt the lines that I incorrectly updated are no longer visible because according to SAP we have received them so I can't deselect them or make them un-highlighted. Is there anyway to undo the changes so that SAP recognises that we haven't yet received these products?
    Any help on rectifying the matter would be much appreciated!

    HI
    If you have taken Backups before that wrong entry,then you can restore it which will put your database with the previous correct entries...
    OR
    You have to reverse those GRPO's or Invoice by posting Returns and Credit memos which will make correction to your wrong stock...

  • IPod unfunctional due to iTunes updating incorrectly!

    I have an 80GB 5th gen iPod. Last night I connecting to the computer and iTunes said an iPod software update was availible, so I clicked to update as usual. Once the update was finished however it became clear this was an error. iTunes has clearly installed the incorrect update to my iPod, the graphics etc now being displayed are from an earlier generation of iPods. Now the only thing I can see to do is restore the iPod, but before I did this I would have to access the files on it in order to hopefully back some of them up (MOST of the music is backed up on my comp, but alot in WMA format, it took me YEEEARS to convert it all, hence I'm currently a bit gutted and angry).
    Anyway, my questions are.. Has anyone else had this problem (seeing as it is an error at Apple's end, their fault and not mine). Is there any way I can access the hard drive even though when I try to access the drive in My Computer it displays as empty? (NOT GOOD). And finally is there any way I could reinstall the correct iPod software without restoring it and so losing all music files etc.
    Please please please help if you can.
    Message was edited by: robwho2

    Same exact thing happened to me, I restored my iPod cause it told me that it was corrupted, even after i restored it and lost over 1k songs it kept telling me it was corrupted. Now it wont even pick up my iPod... I've never been as frustrated with a piece of software as I have been this past week.

  • Contract Release Value is not updated with Confirmation or Invoice value

    The release value for a contract in SRM EBP shows the value of purchase orders created using that contract.  It does not take into account confirmation and/or invoice values.
    For example I create a PO for 10 items at £100/each using Contract ABC.  The total value of the PO is £1000 and the release value contract ABC would be £1000.  If I then only confirm and invoice 5 items (£500) for the PO, the release value of contract ABC stays at £1000 even though I would expect it to update to £500
    Therefore the release value of the contract could be incorrectly overstated if purchase orders are created against the contract but not actually invoiced/confirmed for their total value.
    Please could you confirm the correct functionality and how I could find out the the true invoice value of purchases made using a contract?

    Hi
    <u>Which SRM and R/3 versions are you using ?</u>
    <b>Meanwhile, please go through the following SAP OSS Notes, which will help in this case -></b>
    Note 622045 Net value in release overview of contract is incorrect
    Note 493519 Release quantities are not updated
    Note 1108322 BBP_CONTRACT_CHECK wrong calculation of values
    Note 1102886 Contracts: Lesser Field length for Target Value
    Note 1082548 Check of Released quantity and released value in contract
    Note 656181 Release synchronization of releases on services
    Note 874920 Currency not allowed to be changed for a 'Released' Contract
    Note 703771 Resetting release values during purchase order item deletion
    Note 643823 BLAREL: Incorrect values in service segment
    Note 519879 BBP_CTR_MAIN: No message when values in Contract are reset
    Note 520734 Target value not converted if currency is changed
    Note 528897 Documents not displayed in contract release order overview
    Note 430373 BBP_CON_MNT: No releases available
    Note 491993 Entry of contracts with target values
    Note 437491 Purchase contract: Incorrect update of the call-off values
    Note 406799 BBP_CON_MNT: Fields after contract release ready for input
    Note 398168 Purchase contract: Target value is not changed
    <b>Do let me know.</b>
    Regards
    - Atul

  • Update Rule error while loading the data

    Hello All,
    I tried to do the init load for the datasource 2LIS_02_VAKON (Sales Document Condition), But it error's out in the Update rule saying:
    Short text: Error when generating the update program
    Long Text:  Diagnosis
         An error occurred during program generation for InfoSource 2LIS_11_VAKON
         and InfoProvider 0SD_C15 . This may be extrapolated to incorrect update
         rules.
    Procedure
         Check and correct your update rules and then generate the update program
         again. You can find help on the error in the error log.
    The update rule looks very fine. I even deleted it and re created, but no success..... Please give me your thoughts abt it..... Any suggestions will be great for me.....

    Hello Gokul,
    I could'nt see any analyse button in RSMON. This is the only error message I could get from the Process monitor:
    Short text: Error when generating the update program
    Long Text: Diagnosis
    An error occurred during program generation for InfoSource 2LIS_11_VAKON
    and InfoProvider 0SD_C15 . This may be extrapolated to incorrect update
    rules.
    Procedure
    Check and correct your update rules and then generate the update program
    again. You can find help on the error in the error log.
    Do you expect something else ? Also I went through your OSS note, they are asking to apply support pack 18. Is this a serious issue to apply SP? Because in Quality and Prod it loads fine......
    Please let me know your idea

  • Help with Windows 8.1 Update 1 Offline Deployment using MDT 2013

    Hi guys,
    Hoping that someone has encountered this problem and that there is a simple solution that I am overlooking. Essentially the problem we seem to be having is that after the OS is installed the process of updating the boot partition incorrectly updates
    the boot partition on the offline media, rather than on the local disk. Because UEFI requires boot media to be formatted FAT32 and our deployment is a little on the heavy side (upwards of 40GB) we are generating multi-partition boot media and
    this seems to be creating a problem, our previous Windows 7 offline media (single NTFS partition) worked perfectly. 
    By looking at the BDD.log I can see where it appears to examine the potential boot partitions, finds the local disk boot partition and the external usb hdd boot partition and chooses to write to the external. The task sequence restarts the machine shortly
    thereafter at which point the device cannot boot with an error "No operating system found."
    Thank you in advance for any assistance.

    Hello Erik,
    it seems to be a bug in MDT.
    The routine in ZTIDiskUtility.vbs is looking for the last available boot device:
     For each oWMIDiskPart in AllDiskPartEx ( " WHERE Bootable = TRUE or BootPartition = TRUE " )
      oLogging.CreateEntry "Found bootable drive: " & oWMIDiskPart.Path_ , logTypeVerbose
      set oDiskPart = new ZTIDiskPartition
      set oDiskPart.DiskPart = oWMIDiskPart
      set oDisk = oDiskPart.GetDiskObject
      If oDisk.isOSReady( sOSBuild ) then
       set oLogical = oDiskPart.oWMIDrive( bForced )
       If isValidObject(oLogical) then
        If not bBootFiles then
         oLogging.CreateEntry "Found bootable drive (No Boot File Test) [ " & oLogical.DeviceID & " ]: " & oLogical.Path_ , logTypeInfo
         set GetBootDriveEx = oDiskPart
         ' My change
         Exit For
        ElseIf oFSO.FileExists( oLogical.DeviceID & "\ntldr" ) or oFSO.FileExists( oLogical.DeviceID & "\bootmgr" ) or oFSO.FileExists( oLogical.DeviceID & "\EFI\Microsoft\Boot\bootmgr.efi" ) then
         oLogging.CreateEntry "Found bootable drive [ " & oLogical.DeviceID & " ]: " & oLogical.Path_ , logTypeInfo
         set GetBootDriveEx = oDiskPart
        Else
         oLogging.CreateEntry "No boot files found: " & oLogical.Path_ , logTypeInfo
        End if
       End if
      End if
     next
    I implemented an "Exit For", so you will get the first possible boot drive.

  • DeepMergeClone problem with unsolicited updates

    Hi,
    I am having an odd problem with deepMergeClone and was hoping someone could point me in the correct direction. I am using Weblogic, WebLogicJTSExternalTransactionController, and TopLink 4.6.
    My object model is something like:
    Organization
    - Address
    - Employees(collection of Person)
    - Name, etc...
    Person
    - Address
    - Name, etc...
    Address
    - Region
    - Country
    - Street1, etc...
    The application uses Session Beans that provide TopLink mapped objects to a Servlet layer using Struts. The objects are updated, created, etc. in the Struts actions and then sent to the Session Beans. In the Session Bean we do the something like
    ExternalTransactionController controller = session.getExternalTransactionController();
    UnitOfWork uow = uow = controller.getActiveUnitOfWork();
    uow.readObject(obj); //ensure obj is cached and registered
    uow.deepMergeClone(obj);
    Here is my problem: In the Struts layer, I read a organization by id for an update.
    Updating an organization.address.region will sometimes cause an update to multiple employee's address.region. If you look at the object heirarchy before it gets passed into deepMergeClone, everything looks great.
    If I add code to read the address by id for the organization.address and then set the address into the organization, the update seems to work as expected.
    Is there some rule about needing to register nested objects prior to deepMergeClone? Any other thoughts on what I might be doing wrong?
    Tom

    DeepMergeClone is a very useful feature of TopLink as it allows the application to not have to be concerned with what it changes on the client. The client can traverse any relationships of the objects that are serialized to it (provided the relationships were serialized) and make whatever changes to whatever objects it desires. It can then send the entire object graph back to the server which can does not have to be aware of what the client was doing and can just deepMergeClone everything back into a unit of work and commit the changes to the database.
    Unfortunately the main benefit of deepMergeClone can also be its biggest issue when something goes wrong. DeepMergeClone traverses "everything" related to an object and merges "everything", for complex objects this can occasionally lead to the merging of changes that were not intended or desired by the client.
    Examples can include:
    - Transient attributes. These will be serialized as null so will be merged as null into the unit of work causing incorrect updates to null.
    - Duplicate objects and loss of object identity. Since TopLink is not running on the client, it is possible for the client to violate object identity through retrieving two separately serialized objects from the server that contain relationships to the same object. If these two objects are then related and serialized back to the server and deepMergeClone'd, TopLink will be given two different versions of the same object, this object can be merged twice and one copy can overwrite the other copy. This may be what is occurring with the problem at the start of this thread.
    There is another thread with a similar issue that also links to another thread that has a good description of each of the unit of work merge APIs.
    Re: 1-M deepMergeClone leaves old items in DB
    In general deepMergeClone is a very useful feature, and if you are using it successfully definitely don't stop using it. But if you commonly experience problems, or performance issues, you may wish the consider one of the other merge APIs that give the application more control over what is and is not merged.
    If you are still experiencing the problem and have verified that you are not violating object identity, you will probably need to contact technical support to have them investigate your issue in more detail.

  • Error when generating the update program RSAU484

    Hi,
    I am getting the following error while loading data into customer master  from CRM system
    Error when generating the update program
    Message no. RSAU484
    Diagnosis
    An error occurred during program generation for InfoSource MR_CDB_CUST_HFR and InfoProvider 0BPARTNER$T. This may be extrapolated to incorrect update rules.
    Procedure
    Check and correct your update rules and then generate the update program again. You can find help on the error in the error log.

    Yes,there is just a single line of code in the start routine
    DELETE DATA_PACKAGE WHERE CUSTOMER is initial.
    and update rules  for Business partner and customer market which are object mapped 1:1. No routines or formulaes.
    Could this be a technical issue on the flexible update or a data quality ?

Maybe you are looking for