Workarounds for Hibernate's lack of delete-orphan support for one-to-one and many-to-one relationships?

前端 未结 4 1801
春和景丽
春和景丽 2021-02-05 11:57

Hibernate has no support for \"delete-orphan\" cascading of one-to-one or many-to-one relationships. I recently discovered this, and it\'s giving me a serious headache. I have

相关标签:
4条回答
  • 2021-02-05 12:02

    Write database on update trigger on child table. If parent key is null delete the record from child

    0 讨论(0)
  • 2021-02-05 12:04

    It appears to be a draw back in the framework they MAY address, hopefully soon

    http://opensource.atlassian.com/projects/hibernate/browse/HHH-2608

    That ticket was opened in 2007 and the latest post complaining about the problem was as recent as a month ago.

    What I am doing is putting a property on my object called isMarkedForDeletion. And if that returns true, i have my dao or my service do an explicit delete. It is definintely NOT as good as delete-orphan would be, but it works well enough in the spring+hibernate framework.

    I will keep an eye on this post as this is a VERY important question.

    0 讨论(0)
  • 2021-02-05 12:12

    Heureka, fixed in Hibernate 4.27 https://hibernate.atlassian.net/browse/HHH-6484 (not tested)

    0 讨论(0)
  • 2021-02-05 12:17

    The workaround described here https://forum.hibernate.org/viewtopic.php?p=2379216 worked for me. It uses @OneToMany association with a single element on the "many" side to implement a @OneToOne association and solve the remove-orphans problem.

    0 讨论(0)
提交回复
热议问题