Monday, September 19, 2011

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at com.EmpHome.attachsaveorupdate(EmpHome.java:137)
at com.EmpHome.main(EmpHome.java:76)


Solution
This Exception will arise in different scenario of save and saveOrupdate method of hibernate.
if Object is transient , need to save may occur this exception
Conditions.
1. Flushing the data before committing the object may lead to clear all object pending for persist.
2. If object has primary key which is auto generated and you are forcing has assigned key may cause the exception.
3. if you are cleaning the object before committing the object to database may lead this exception.
4. Zero or Incorrect ID:
Hibernate excepts an primary or id of null (not initialize while saving) has per point 2 to mean the object was not saved. If you set the ID to zero or something else, Hibernate will try to update instead of insert, or it lead may to throw this exception.
5.
Object Doesn’t Exist: This is the most easy to determine : has the object get deleted somehow? If so, trying to delete once again it will throw this exception.
6.
Object is Stale: Hibernate caches objects from the session. If the object was modified, and Hibernate doesn’t know about it, it will throw this exception — note the StaleStateException part of the exception.

so after committing the object to database need to flush or clear or clean it ,not before.

122 comments:

  1. This problem mainly occurs when we are trying to save or update the object which are already fetched into memory by a running session. For e.g. if i am trying to fetch an object into memory and setting the members of that object into another object then this prob will occur.

    for e.g. class person's object is a member of class men then if i fetch the object of men and set it to another object and trying to save the new object will raise this exception.

    ReplyDelete
    Replies
    1. So what is the solution for this? As you said I'm doing the same thing, I have all ready fetched an object into memory and copying the members of that object into another.

      Delete
  2. what's the solution

    ReplyDelete
  3. So what do you mean by "committing the object" What is the syntax of the statement to do that? Are you talking about "session.Commit" or something else?

    ReplyDelete
  4. Stale state means
    Hibernate caches objects from the session. If the object was modified, and Hibernate doesn’t know about it then this exception is thrown. This will mainly occurs when 2 or 3 user try to acquire the object and modify but others are not reflected with that state.


    1. This can be resolved by updating the object from database like refresh method in hibernate and then commit will persist the object in db.

    2. You can use merge method and commit, But it is risky since it will override with current data.

    3. Using lock can also be resolved.

    ReplyDelete
  5. Welcome Post very usefull informatation.and

    iam expecting more posts like this please keep updating us........

    ReplyDelete
  6. very useful information . for Microsoft Dynamics CRM Training Online courses Microsoft Dynamics CRM Training Online

    ReplyDelete
  7. Thanks For Sharing Your Information , Plaese Keep Updating US, Time Went On Reading The Articlehttps://nareshit.in/java-online-training/

    ReplyDelete
  8. Thanks For Sharing Your Information , Plaese Keep Updating US

    CEH Training In Hyderbad

    ReplyDelete
  9. Thank you for giving the information and it is use full for me. training with placement in Hyderabad

    ReplyDelete
  10. thank your valuable content.we are very thankful to you.one of the recommanded blog.which is very useful to new learners and professionals.content is very useful for hadoop learners


    Best Spring Classroom Training Institute
    Best Devops Classroom Training Institute
    Best Corejava Classroom Training Institute
    Best Advanced Classroom Training Institute
    Best Hadoop Training Institute
    Best PHP Training Institute

    ReplyDelete
  11. Thank you for sharing your awesome and valuable article this is the best blog for the students they can also learn.

    Workday Online Training

    ReplyDelete
  12. wow really such a helpful article you had posted. Definitely it will be useful for many people. Thank you so much

    ReplyDelete
  13. I like the post format as you create user engagement in the complete article. It seems round up of all published posts. Thanks for gauging the informative posts.Microsoft Dynamics 365

    ReplyDelete
  14. Hi, Thanks for sharing such a great article. It's east to understand for everyone.

    ReplyDelete
  15. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing....mulesoft 4 training

    ReplyDelete
  16. We as a team of real-time industrial experience with a lot of knowledge in developing applications in python programming (7+ years) will ensure that we will deliver our best in python training in vijayawada. , and we believe that no one matches us in this context.

    ReplyDelete
  17. This post is really nice and informative. The explanation given is really comprehensive and informative.


    mule esb training

    ReplyDelete
  18. I find this blog to be very interesting and very resourceful. I would say that your blogs are really interesting and informative for me and this article explained everything in detail.
    Best pathology in lucknow
    Best pathology in jankipuram
    Diagnostic centre in lucknow
    X-ray pathology in jankipuram
    Best diagnostic centre in lucknow
    Pathology centre in jankipuram

    ReplyDelete
  19. This post is really nice and informative. The explanation given is really comprehensive and informative. devops training courses by 10+ years experienced faculty.

    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete
  21. AWS
    Mind Q Systems provides AWS training in Hyderabad & Bangalore.AWS training designed for students and professionals. Mind Q Provides 100% placement assistance with AWS training.

    Mind Q Systems is a Software Training Institute in Hyderabad and Bangalore offering courses on Testing tools, selenium, java, oracle, Manual Testing, Angular, Python, SAP, Devops etc.to Job Seekers, Professionals, Business Owners, and Students. We have highly qualified trainers with years of real-time experience.


    ReplyDelete

  22. Wow. That is so elegant and logical and clearly explained. Brilliantly goes through what could be a complex process and makes it obvious.I want to refer about the tableau online training in hyderabad and tableau tutorial videos

    ReplyDelete
  23. This Was An Amazing ! I Haven't Seen This Type of Blog Ever ! Thankyou For Sharing, data science course in Hyderabad

    ReplyDelete
  24. Thanks a lot for sharing it, that’s truly has added a lot to our knowledge about this topic. Have a more success ful day. always find something interesting.
    Data Science Training In Hyderabad

    ReplyDelete
  25. KloudWIFI truly believes that reliable, fast networks have been the game changers in driving innovation, productivity and instant collaboration supported by the relentless growth of convenient cloud-hosted applications. Even with a powerful, proven network infrastructure like Cisco Meraki and Ekahau, the end user experience can only be truly optimized by considering all the internal and external factors to the end user experiences. meraki insight partner in hyderabad

    ReplyDelete
  26. hanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    servicenow online training
    best servicenow online training
    top servicenow online training

    ReplyDelete
  27. Awesome blog, I enjoyed reading your articles. This is truly a great read for me.
    DevOps Training
    DevOps Online Training
    DevOps Training in Ameerpet

    ReplyDelete
  28. Writers are a unique breed. You know when you're reading content written by an expert, or at least a very intelligent writer. This article is virtually perfect in my opinion.
    Best Data Science training in Mumbai

    Data Science training in Mumbai

    ReplyDelete
  29. Get extremely comfortable rides from and to Charles M. Schulz–Sonoma County Airport Limo Transfer and enjoy your journey.

    ReplyDelete
  30. Hey, i liked reading your article. You may go through few of my creative works here
    Jobs.promaxbda
    Publicatom

    ReplyDelete
  31. This comment has been removed by the author.

    ReplyDelete
  32. Very informative articles for java developers. I will share power bi training videos for Business Intelligence Managers.

    ReplyDelete
  33. Wow. That is so elegant and logical and clearly explained. Brilliantly goes through what could be a complex process and makes it obvious.I want to refer about the best DevOps Training in Chennai | DevOps Training in anna nagar | DevOps Training in omr | DevOps Training in porur | DevOps Training in tambaram | DevOps Training in velachery

    ReplyDelete
  34. Hi, I am Veronica Kate. I am working as a full-time academic consultant with Livewebtutors. We are providing Dissertation Editing Service and Deakin Referencing Generator to university and college students across the globe. I have been successfully helping students, scholars and professionals in various services like I mentioned above for more than 5 syears and hold excellent writing, proofreading and editing skills. You would also find various academic tools on Livewebtutors like Paraphrasing Tool and Harvard Referencing Generator.

    ReplyDelete

  35. First of all i am saying that i like your post very much.I am really impressed by the way in which you presented the content and also the structure of the post. Hope you can gave us more posts like this and i really appreciate your hardwork.

    python training in bangalore

    python training in hyderabad

    python online training

    python training

    python flask training

    python flask online training

    python training in coimbatore


    ReplyDelete
  36. Am really impressed about this blog because this blog is very easy to learn and understand clearly.This blog is very useful for the college students and researchers to take a good notes in good manner,I gained many unknown information.



    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training

    ReplyDelete
  37. https://michalbe.blogspot.com/2010/09/simple-game-with-html5-canvas-part-1.html?showComment=1601184940428#c1538146676451867420

    ReplyDelete

  38. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.I want to share about Mulesoft training .

    ReplyDelete
  39. https://omari-o.blogspot.com/2009/09/aspnet-white-space-cleaning-with-no.html?showComment=1601906739232#c1827469288899022926

    ReplyDelete
  40. huuuuh, its a really useful article, thanks for sharing off plan properties

    ReplyDelete
  41. This is my first time visit to your blog and I am very interested in the articles that you serve. Provide enough knowledge for me. Thank you for sharing useful and don't forget, keep sharing useful info:

    Java training

    ReplyDelete
  42. software testing company in India
    software testing company in Hyderabad
    very useful information.
    nice and informative article for java developers.
    Thanks for sharing this information with us.

    ReplyDelete
  43. I am really happy to say it’s an interesting post to read . I learn new information from your article , you are doing a great job . Keep it up

    Devops Training in Hyderabad

    Hadoop Training in Hyderabad

    Python Training in Hyderabad

    ReplyDelete
  44. This comment has been removed by the author.

    ReplyDelete
  45. Prefer to study this kind of material. Nicely written information in this post, the quality of content is fine and the conclusion is lovely.
    Spring Bootand Micro services Training in Gurgaon
    Java Training in Gurgaon
    Android Training in Gurgaon

    ReplyDelete
  46. Nice post!

    Worried About QuickBooks Error ?Get in touch with QuickBooks expert for instant solution.
    Click Here to know how to fix QuickBooks Error 8007

    Dial on QuickBooks Error Phone Number +1-855-977-7463.

    ReplyDelete
  47. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously
    in their life, he/she can earn his living by doing blogging.Thank you for this article.
    top tibco sportfire online training

    ReplyDelete
  48. Shreeja Health Care is leading manufacturer of Oil Maker Machine. Shreeja Oil Extraction Machine is able to extract oil from various seeds like peanuts, Coconut, Sesame, Soybean, macadamia nuts, walnuts, sunflower seeds, vegetable seeds flaxseed etc.

    ReplyDelete
  49. Nice & Informative Blog !

    QuickBooks Error PS032 is a highly disruptive error that can happen when you are downloading the updates of QuickBooks.Our experts are diverse and talented in fixing all the malicious errors of QuickBooks.

    ReplyDelete
  50. Shreeja Health Care is leading manufacturer of Mini oil Maker Machine. Shreeja Oil Extraction Machine is able to extract oil from various seeds like peanuts, Coconut, Sesame, Soybean, macadamia nuts, walnuts, sunflower seeds, vegetable seeds flaxseed et

    ReplyDelete
  51. I am getting the same exception. Recently we upgraded to oracle 19c from 18. Issue started coming since the upgrade.

    ReplyDelete
  52. Data science is the study of data. It involves developing methods of recording, storing, and analyzing data to effectively extract useful information. The goal of data science is to gain insights and knowledge from any type of data — both structured and unstructured. so thanks for sharing these information.
    Data Science Training in Gurgaon
    Bigdata Hadoop Training in Gurgaon
    Machine Learning TrDevops Training in Gurgaontraining in Gurgaon

    ReplyDelete
  53. Very Good Article Get instant & Latest Updated Satta King result of Satta King Gali Result Faridabad Result Ghaziabad Result, Desawar Result , Panihari satta result, aghori satta Result And Many More Result Go Through bhutni Satta King .We are Provide fast And 100% Accurate Results.

    ReplyDelete
  54. Hey! If you are looking for the authentic help for QuickBooks Customer Service issues then look no further than QuickBooks Customer Service+1-855-738-7873

    ReplyDelete
  55. Hey! If you are looking for the authentic help for QuickBooks Customer Service issues then look no further than QuickBooks Customer Service+1-855-444-2233

    ReplyDelete
  56. Hey! If you are looking for the authentic help for QuickBooks Customer Service issues then look no further than QuickBooks Customer Service+1-877-948-5867

    ReplyDelete

  57. Hey! What a wonderful blog. I loved your blog. QuickBooks is the best accounting software, however, it has lots of bugs like QuickBooks Error. To fix such issues, you can contact experts via QuickBooks Customer Support Number

    ReplyDelete
  58. Hey! Lovely blog. Your blog contains all the details and information related to the topic. In case you are a QuickBooks user, here is good news for you. You may encounter any error like QuickBooks Error, visit at QuickBooks Customer Service Phone Number for quick help.

    ReplyDelete
  59. This is great collection of shotguns at British shooting show. Fury Jacket

    ReplyDelete
  60. Hey! Mind-blowing blog. Keep writing such beautiful blogs. In case you are struggling with issues on QuickBooks for MAC Support , dial QuickBooks Support Phone Number (855)428-7237. The team, on the other end, will assist you with the best technical services.

    ReplyDelete
  61. Really awesome blog. Informative content and useful to my people. Thanks for sharing this blog with us.
    Data Science Training Institute in Hyderabad

    ReplyDelete

  62. Candela GentleLASE medical grade laser applies precise, controlled pulses of laser. Auckland Laser Hair Removal energy that reach down the hair shaft into the follicle underneath the skin, cauterizing the hair at its root. the encompassing tissue or skin isn’t damaged. The laser’s gentle beam of sunshine damages and consequently prevents the follicle from growing.

    ReplyDelete
  63. Shreeja Oil Maker is a global leading manufacturer, wholesaler, supplier, exporter of various small scale machinery. Shreeja oil maker machine or Mini oil extraction machine is one of our innovative product which is able to extract 100% pure oil from the various seed. This is also known as a Oil Extraction Machine or mini oil Ghani. We have a stronghold in national as well as a worldwide market.

    ReplyDelete
  64. Гадания на будущее с толкованием - это простой прием поворожить с употреблением всевозможных атрибутов и методов. Магические силы и разного рода способы ворожения научно не подтверждены, однако многие люди верят в это. Перечень деяний, направленных на предсказание будущего, называют гадание.

    ReplyDelete
  65. It was not first article by this author as I always found him as a talented author. Fonzie Leather Jacket

    ReplyDelete
  66. Thanks for sharing. This blog post was really amazing!
    visit: -swhizz
    <a href="https://www.swhizz.com/salesforce-training/>salesforce</a>


    ReplyDelete
  67. Nice blog is very useful information that i have found. Thanks for sharing and please keep updating us.
    visit us: -swhizz
    our services: -
    Salesforce
    DevOps
    Testing

    ReplyDelete
  68. Very Informative post. Will help students and professional. Keep up the good work. Thanks https://www.javatutoronline.com

    ReplyDelete
  69. Save Money With Solar Energy ! Power costs can be reduced in the long run by having the best solar System provider help in installing a solar system.

    ReplyDelete