StaleObjectstateException row was updated or deleted by

前端 未结 4 1591
遇见更好的自我
遇见更好的自我 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:26

    This problem was something that I had experienced and was quite frustrating, although there has to be something a little odd going on in your DAO/Hibernate calls, because if you're doing a lookup by ID there is no reason to get a stale state, since that is just a simple lookup for an object.

    First, make sure all your methods are annotated with @Transaction(required=true) // you'll have to look up the exact syntax

    However, this exception is usually thrown when you try to make changes to an object that has been detached from the session it was retrieved from. The solution to this is often not simple and would require more code posted so we can see exactly what is going on; my general suggestion would be to create a @Service that performs these kinds of things within a single transaction

提交回复
热议问题