在休眠"deleted object would be re-saved by cascade"中删除父子对象时出现问题



我有以下两个实体:

1- 交易

@OneToMany(cascade=CascadeType.ALL,mappedBy = "deal", fetch = FetchType.EAGER)
@Fetch( FetchMode.SELECT)
private List<DealCheckList> dealCheckList;

2- 交易清单

@JoinColumn(name = "DEAL_ID", referencedColumnName = "DEAL_ID", insertable = false, updatable = false)
@ManyToOne(fetch = FetchType.LAZY)  
private Deal deal;

在做session.delete(deal)时,我收到以下错误

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

请帮忙。

这可能意味着您尝试删除的对象是某个其他集合的子级。为对象设置 cascade="all" 意味着它的子对象将被自动删除/更新,除非它们不属于其他父级。

您必须从其父集合中删除尝试删除的对象。

例:

objectBeingDeleted.getParent().getChildren().remove(objectBeingDeleted); 

然后你可以做

session.delete(objectBeingDeleted);

祝你好运

您有一个仍然引用此交易的DealCheckList对象,并且需要在通过休眠调用删除交易之前在 Java 中将其从那里删除。

相关内容

  • 没有找到相关文章

最新更新