我有以下两个实体:
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 中将其从那里删除。