[英]Get ID of all deleted entities when parent is removed?
Lets say I have a Parent object that have several children with cascadeType = CascadeType.REMOVE, orphanRemoval = true
. 可以说我有一个Parent对象,其中有几个孩子,其
cascadeType = CascadeType.REMOVE, orphanRemoval = true
。 Is it possible to collect everything that was deleted when the parent was removed? 是否可以收集在删除父级时删除的所有内容?
If I log all sql queries I could see that multiple deletes is executed. 如果我记录所有SQL查询,则可以看到已执行多次删除。 But I no idea how to get all ids back.
但我不知道如何获取所有ID。
You can use @PreRemove which will be called whenever you try to remove an Entity. 您可以使用@PreRemove,只要您尝试删除实体,就会调用它。
I have used this for Audit purpose to keep track of Removed Records. 我已将其用于审核目的,以跟踪已删除记录。
@Entity
public class Actor extends AbstractBusinessObject{
@ManyToMany(mappedBy = "cast")
private Set<Movie> movies;
// setters and getters
@PreRemove
private void removeActorFromMovies() {
//Executed before the entity manager remove operation is actually
// executed or cascaded. This call is synchronous with the remove operation.
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.