具有两个父类的子类上的 Hibernate 全部删除孤儿
我正在研究一个问题,其中有两个“父”类 P 和 Q 将所有删除孤儿级联到“子”类 C。我在 Hibernate 中的直觉告诉我这确实是一个坏主意,我当代码删除 P 的实例(即 session.delete(myP); )时收到一条错误消息,该消息可能证实了这一点:
“已删除的对象将通过级联重新保存(从关联中删除已删除的对象):[C#1] “
当 P 的实例和 Q 的实例都可以充当同一个 C 实例的父类时,任何人都可以确认为单个子类拥有两个父类是一个坏主意吗?
谢谢!
I'm looking into a problem, where there are two "parent" classes, P and Q that cascade all-delete-orphan to a "child" class, C. My intuition in Hibernate tells this is really a bad idea and I am getting an error message that probably confirms this when the code deletes an instance of P (i.e. session.delete(myP); ):
"deleted object would be re-saved by cascade (remove deleted object from associations): [C#1]"
Can anyone confirm that having having two parent classes for a single child class is a bad idea when an instance of P and instance of Q can both act as the parent for the same instance of C?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,如果您在同一个事务中同时拥有 P 和 Q,同时更新 P 并从 Q 中删除(反之亦然),那么这只会成为问题。双重父母身份只会给交易增加一层复杂性,但它仍然应该按照您期望的方式运作。
My guess is that is only going to be a problem if you have both P and Q in the same transaction, simultaneously updating P and deleting from Q (or vice versa). Double parenthood should just add a layer of complexity to the transaction but it should still work the way you would expect.