org.springframework.orm.ObjectOptimisticLockingFailureException with microsoft driver and not with jtds...












0















I am getting ObjectOptimisticLockingFailureException with batch update when I use microsoft sqlserver driver (sqljdbc4.jar). However with the same code, when I switch the driver to Jtds driver, I am able to succesfully do batch update and insert. we are using sql server database and JPA with Hibernate.



Below is what I am doing.




  1. Get the data from the database with status_code as SUBMITTED and
    current flag as Y.


  2. Batch Update the records to current flag N and Batch insert new record with new status BATCH_LOCKED.


  3. Batch update the above records again with current flag N and batch insert new record with status COMPLETED.


All these updates go through fine. When the transaction is committing, I am getting the exception below



I am not specifically defining Optimistic locking and nor have i defined @Version annotation for any column. How does the Optimistic locking happening by default?



If I comment the Step #3, then I do not get the exception.



Why do I not get the exception with JTDS driver?




org.springframework.orm.ObjectOptimisticLockingFailureException: Batch
update returned unexpected row count from update [1]; actual row
count: 0; expected: 1; nested exception is
org.hibernate.StaleStateException: Batch update returned unexpected
row count from update [1]; actual row count: 0; expected: 1











share|improve this question





























    0















    I am getting ObjectOptimisticLockingFailureException with batch update when I use microsoft sqlserver driver (sqljdbc4.jar). However with the same code, when I switch the driver to Jtds driver, I am able to succesfully do batch update and insert. we are using sql server database and JPA with Hibernate.



    Below is what I am doing.




    1. Get the data from the database with status_code as SUBMITTED and
      current flag as Y.


    2. Batch Update the records to current flag N and Batch insert new record with new status BATCH_LOCKED.


    3. Batch update the above records again with current flag N and batch insert new record with status COMPLETED.


    All these updates go through fine. When the transaction is committing, I am getting the exception below



    I am not specifically defining Optimistic locking and nor have i defined @Version annotation for any column. How does the Optimistic locking happening by default?



    If I comment the Step #3, then I do not get the exception.



    Why do I not get the exception with JTDS driver?




    org.springframework.orm.ObjectOptimisticLockingFailureException: Batch
    update returned unexpected row count from update [1]; actual row
    count: 0; expected: 1; nested exception is
    org.hibernate.StaleStateException: Batch update returned unexpected
    row count from update [1]; actual row count: 0; expected: 1











    share|improve this question



























      0












      0








      0








      I am getting ObjectOptimisticLockingFailureException with batch update when I use microsoft sqlserver driver (sqljdbc4.jar). However with the same code, when I switch the driver to Jtds driver, I am able to succesfully do batch update and insert. we are using sql server database and JPA with Hibernate.



      Below is what I am doing.




      1. Get the data from the database with status_code as SUBMITTED and
        current flag as Y.


      2. Batch Update the records to current flag N and Batch insert new record with new status BATCH_LOCKED.


      3. Batch update the above records again with current flag N and batch insert new record with status COMPLETED.


      All these updates go through fine. When the transaction is committing, I am getting the exception below



      I am not specifically defining Optimistic locking and nor have i defined @Version annotation for any column. How does the Optimistic locking happening by default?



      If I comment the Step #3, then I do not get the exception.



      Why do I not get the exception with JTDS driver?




      org.springframework.orm.ObjectOptimisticLockingFailureException: Batch
      update returned unexpected row count from update [1]; actual row
      count: 0; expected: 1; nested exception is
      org.hibernate.StaleStateException: Batch update returned unexpected
      row count from update [1]; actual row count: 0; expected: 1











      share|improve this question
















      I am getting ObjectOptimisticLockingFailureException with batch update when I use microsoft sqlserver driver (sqljdbc4.jar). However with the same code, when I switch the driver to Jtds driver, I am able to succesfully do batch update and insert. we are using sql server database and JPA with Hibernate.



      Below is what I am doing.




      1. Get the data from the database with status_code as SUBMITTED and
        current flag as Y.


      2. Batch Update the records to current flag N and Batch insert new record with new status BATCH_LOCKED.


      3. Batch update the above records again with current flag N and batch insert new record with status COMPLETED.


      All these updates go through fine. When the transaction is committing, I am getting the exception below



      I am not specifically defining Optimistic locking and nor have i defined @Version annotation for any column. How does the Optimistic locking happening by default?



      If I comment the Step #3, then I do not get the exception.



      Why do I not get the exception with JTDS driver?




      org.springframework.orm.ObjectOptimisticLockingFailureException: Batch
      update returned unexpected row count from update [1]; actual row
      count: 0; expected: 1; nested exception is
      org.hibernate.StaleStateException: Batch update returned unexpected
      row count from update [1]; actual row count: 0; expected: 1








      java hibernate jtds sqljdbc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 6:50









      Aditya Sharma

      4851416




      4851416










      asked Nov 13 '18 at 1:12









      MeghaMegha

      11




      11
























          1 Answer
          1






          active

          oldest

          votes


















          0














          In step 3 when you try to update the same entries, the value has been changed in step 1 and 2. So either you need to read the updated data again and then update it.



          The Optimistic Locking Exception prevents lost updates and you shouldn't ignore it. You can simply catch it in a common exception handler and redirect the user to the current workflow starting point, indicating there was a concurrent change that he was not aware of.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272352%2forg-springframework-orm-objectoptimisticlockingfailureexception-with-microsoft-d%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            In step 3 when you try to update the same entries, the value has been changed in step 1 and 2. So either you need to read the updated data again and then update it.



            The Optimistic Locking Exception prevents lost updates and you shouldn't ignore it. You can simply catch it in a common exception handler and redirect the user to the current workflow starting point, indicating there was a concurrent change that he was not aware of.






            share|improve this answer




























              0














              In step 3 when you try to update the same entries, the value has been changed in step 1 and 2. So either you need to read the updated data again and then update it.



              The Optimistic Locking Exception prevents lost updates and you shouldn't ignore it. You can simply catch it in a common exception handler and redirect the user to the current workflow starting point, indicating there was a concurrent change that he was not aware of.






              share|improve this answer


























                0












                0








                0







                In step 3 when you try to update the same entries, the value has been changed in step 1 and 2. So either you need to read the updated data again and then update it.



                The Optimistic Locking Exception prevents lost updates and you shouldn't ignore it. You can simply catch it in a common exception handler and redirect the user to the current workflow starting point, indicating there was a concurrent change that he was not aware of.






                share|improve this answer













                In step 3 when you try to update the same entries, the value has been changed in step 1 and 2. So either you need to read the updated data again and then update it.



                The Optimistic Locking Exception prevents lost updates and you shouldn't ignore it. You can simply catch it in a common exception handler and redirect the user to the current workflow starting point, indicating there was a concurrent change that he was not aware of.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 4:26









                Pooja AggarwalPooja Aggarwal

                880211




                880211






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272352%2forg-springframework-orm-objectoptimisticlockingfailureexception-with-microsoft-d%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Full-time equivalent

                    さくらももこ

                    13 indicted, 8 arrested in Calif. drug cartel investigation