5 Replies Latest reply: Feb 19, 2013 10:20 AM by RahulB RSS

    SaveEdit failed to validate in concurrent requests.

    925948
      We have a record, got two fields AAA and BBB, for some business reason, the combination of the two fields has to be unique.
      There is another field is the key of record we can not change.
      So we have validation in SearchSave event of "Add search record" of the Component, and validation in SaveEdit of the record.

      In most cases, it works fine, however a customer somehow was able to create two rows of record with the same combination of AAA and BBB.
      We did some simulation by opening two browsers at the same time and clicking the push button (DoSave in the FieldChange event)
      And two rows of records indeed were successfully inserted.

      Apparently, SaveEdit failed to validate in these concurrent requests, and the following table may show the sequence of the code executed in two sessions.

      ---Sequence---|---Session------------------|---Session 2----------------|
      ______________________________________________________
      ---1-------------|---Saveedit check pass---|------------------------------|
      ---2-------------|------------------------------|---SaveEdit check Pass---|
      ---3-------------|---Insert--------------------|------------------------------|
      ---4-------------|------------------------------|---Insert--------------------|

      The ideal execution is the SaveEdit and Insert within one session are treated as atomic/transaction, that before the SaveEdit was triggered, the table is locked, and then release after Insert.

      I tried the following approaches:
      1. Change DoSave() to DoSaveNow(), better, but not always works
      2. Add a unique index to AAA and BBB, but I personally don't buy in it for the following reasons:
      a) We cannot use unique index everywhere for such scenarios
      b) If the record is allowed to be logical deleted (by using a deleted flag field), it is possible to have more than one row that deleted but same for combination of AAA and BBB, then index approach will not work

      Please someone give me suggestions.
        • 1. Re: SaveEdit failed to validate in concurrent requests.
          HakanBiroglu
          Why do you choose not to set the two fields AAA and BBB as keys on your record, this will generate a unique index and disable the possibility of duplicate records.
          No coding needed what so ever, the component buffer processing will handle the uniqueness.

          Hakan
          • 2. Re: SaveEdit failed to validate in concurrent requests.
            RahulB
            I agree with Hakan....


            But i understand you can not change the record.....is it possible to create a simple view on the same record (may be fetch all columns from that record)...and make AAA and BBB as additional keys....and use that view on the page instead of the record?
            If the view is simple, PS allows to insert row in them on a page like any physical SQL-Table type Record.

            Let me know if this helps.
            • 3. Re: SaveEdit failed to validate in concurrent requests.
              925948
              Thanks for the suggestion, the reason that I cannot set these two fields as keys is we have another field as key already.

              Actually, I think this is a business validation, and business validation can various, not all scenarios can be resolved by unique index, so I'm seeking another way, for example:
              An employee can request up to 10 days’ vacation a year
              If the record is allowed to be logical deleted (by using a deleted flag field), it is possible to have more than one row that deleted but same for combination of AAA and BBB
              • 4. Re: SaveEdit failed to validate in concurrent requests.
                925948
                Thanks for the suggestion, the reason that I cannot set these two fields as keys is we have another field as key already.

                Actually, I think this is a business validation, and business validation can various, not all scenarios can be resolved by unique index, so I'm seeking another way, for example:
                An employee can request up to 10 days’ vacation a year
                If the record is allowed to be logical deleted (by using a deleted flag field), it is possible to have more than one row that deleted but same for combination of AAA and BBB
                • 5. Re: SaveEdit failed to validate in concurrent requests.
                  RahulB
                  I am not sure if i understood your example....The vacation thing that you mentioned is new for me and does not fit in with the issue description you mentioned early.

                  However, I can conclude 2 things:
                  1. Either your issue is resolved OR
                  2. you can still try the solution i suggested and see if it works for you.

                  Thanks,
                  Rahul