StaleStateException when saving entity with complex relations

前端 未结 2 1098
忘掉有多难
忘掉有多难 2021-01-02 20:06

The hibernate entity I am saving in the database (Oracle) has very complex relations, in the sense that it has many related entities. It looks something like this...

<
2条回答
  •  醉酒成梦
    2021-01-02 20:52

    This happened to me under the following circumstances:

    • I created objectA in java code.
    • I added extant objectB to objectA as a field. objectB has a one to one relation with objectA.
    • I saved(created) objectA in the database.
    • When objectA was saved, objectB was updated in the database to add the id of objectA.

    • Then I added an objectC to objectA (one objectA for many objectCs). I tried to update objectA and got the stalestateexception....even when using merge.

    The answer is that I needed to either update objectB or retrieve a fresh istance of objectA from the database

提交回复
热议问题