StaleObjectstateException row was updated or deleted by

前端 未结 4 1588
遇见更好的自我
遇见更好的自我 2020-12-30 04:10

I am getting this exception in a controller of a web application based on spring framework using hibernate. I have tried many ways to counter this but could not resolve it.<

4条回答
  •  借酒劲吻你
    2020-12-30 04:18

    Here are 3 possibilities (as I do not know exactly, which kind of hibernate session handling you are using). Add one after another and test:

    Use bi-directional mapping with inverse=true between parent object and child object, so the change in parent or child will get propagate to the other end of relation properly.

    Add support for Optimistic Locking using TimeStamp or Version column

    Use join query to fetch the whole object graph [ parent+children] together to avoid the second call altogether.

    Lastly, if and only if nothing works: Load the parent again by Id (you have that already) and populate modified data then update.

    Life will be good! :)

提交回复
热议问题