org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations):

前端 未结 4 874
面向向阳花
面向向阳花 2020-12-09 11:42

i am getting the above error \"org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): \". could someone

4条回答
  •  [愿得一人]
    2020-12-09 12:15

    If you are doing this via XML (and not annotations), below is a solution which worked for me:

    One-to-Many Associations:

    1. Remove any link of the child object from any collections in the parent object [NOTE: If you are doing One-to-One association, just set the child object reference in the parent object to "null"]
    2. Delete the child object from the database
    3. flush the changes using session.flush()
    4. Link the parent object to the new child object
    5. Save the parent object 6) commit the changes

    CAUTION: session.flush() is important as the Hibernate needs to see the changes,

    If you cannot flush the session, I would advise you to do steps (1,2) in a different transaction and then do steps (4,5,6) in a new transaction.

提交回复
热议问题