删除东西“A”在休眠中不用“A”的集合更新对象。 [英] Deleting thing "A" in hibernate does not update objects with collections of "A"

查看:143
本文介绍了删除东西“A”在休眠中不用“A”的集合更新对象。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说你有一只猫,和小猫。然后你对属于猫的小猫做了删除()。

Say you had a Cat, with Kittens. Then you you did a delete() on a kitten that belongs to a Cat. The Cat object still has a reference to the deleted kitten, until the session closes.

避免这种情况的优雅方法是什么?

What's an elegant way to avoid this situation?

推荐答案

您应该从相关Cat的集合中删除Kitten,然后存储更新的Cat。在您的hibernate配置中,Cat和Kitten的级联为all,delete-orphan将从持久集合中删除。

You should delete the Kitten from the collection of its associated Cat then store the updated Cat. In your hibernate configuration set cascade to "all,delete-orphan" for Cat and the Kitten will be removed from the persisted collection.

这篇关于删除东西“A”在休眠中不用“A”的集合更新对象。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆