在Hibernate中,删除存在关联关系的一个对象时,会出现 org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)这个异常
解决方案如下:
方法1 删除Set方的cascade
方法2 解决关联关系后,再删除 :
Attachment attachment = attachments.get(i);
content.getAttachments().remove(attachment);
attachment.setContent(null);
removeObject(attachment);
方法3 在many-to-one方增加cascade 但值不能是none
如果以上三个方案都失败(哼哼~ 我用了5个小时才找出来的)
检查一下hashCode equals是否使用了id作为唯一标示的选项了;我用uuid.hex时是没有问题的;
但是用了native,就不行了,怎么办?删除啊!
也就是问题出现在本文给出的持久化类的hashCode equals方法身上
解决方案如下:
方法1 删除Set方的cascade
方法2 解决关联关系后,再删除 :
Attachment attachment = attachments.get(i);
content.getAttachments().remove(attachment);
attachment.setContent(null);
removeObject(attachment);
方法3 在many-to-one方增加cascade 但值不能是none
如果以上三个方案都失败(哼哼~ 我用了5个小时才找出来的)
检查一下hashCode equals是否使用了id作为唯一标示的选项了;我用uuid.hex时是没有问题的;
但是用了native,就不行了,怎么办?删除啊!
也就是问题出现在本文给出的持久化类的hashCode equals方法身上
发表评论
- 浏览: 67455 次
- 性别:


- 详细资料
搜索本博客
最近加入圈子
链接
最新评论
-
Hibernate之deleted obje ...
不错,我也碰到这个问题了。
-- by winwnx -
Java 接口大全、面向接口 ...
厉害!学习了。谢谢!
-- by 31212 -
ET Limit方式的分页查询
不能排序怎么办办呢
-- by zhang20084 -
eXtreme Table 的基本用法 ...
为什么 我把的CSS不能调用?把TEST里面的<STYLE>去掉后,调用e ...
-- by fredweng -
分页标签:pager-taglib使 ...
发现LZ在没有声明的情况下引用了我大部分的文字。连“咳”都用过来了 :)http ...
-- by 我想我是海






评论排行榜