deleted object would be re-saved by cascade (remove deleted object from associations)

后端 未结 18 1148
轮回少年
轮回少年 2020-11-30 00:19

i have the following two entities:

1- PlayList:

@OneToMany(fetch = FetchType.EAGER, mappedBy = \"playlist\", orphanRemoval = true, c         


        
18条回答
  •  遥遥无期
    2020-11-30 00:57

    I encountered this exception message as well. For me the problem was different. I wanted to delete a parent.

    In one transaction:

    • First I called up the parent from the database.
    • Then I called a child element from a collection in the parent.
    • Then I referenced one field in the child (id)
    • Then I deleted the parent.
    • Then I called commit.
    • I got the "deleted object would be resaved" error.

    It turns out that I had to do two separate transactions. I committed after referencing the field in the child. Then started a new commit for the delete.

    There was no need to delete the child elements or empty the collections in the parent (assuming orphanRemoval = true.). In fact, this didn't work.

    In sum, this error appears if you have a reference to a field in a child object when that object is being deleted.

提交回复
热议问题