简体   繁体   English

获取删除父级后所有已删除实体的ID?

[英]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.

相关问题 休眠:如何确保在父级的所有子实体都删除后不删除父级? - Hibernate: How to ensure that a parent is not deleted when all its child entities are? 比较子实体列表时获取父实体ID - Get parent entity ID when comparing list of child entities 当我删除一个实体时,相关的实体被删除并出现错误 - When I delete an entity, the entities related are deleted and get an error 如何获取已删除实体的数量 - How to get the count of deleted entities 在Play框架中删除父级时,不会为子实体调用Model.delete() - Model.delete() not called for child entities when parent is deleted in Play Framework 在JPA双向@OnetoMany关系中,当我更新父实体时,数据库中的子实体被删除 - In JPA bidirectional @OnetoMany relationship, when I update the parent entity, the child entities are deleted in database 如何在使用Hibernate删除父项时删除所有子行? - How to delete all child rows when parent is deleted using Hibernate? 正在从数据库中删除特定用户的所有通知,此时只应删除一个 - All notifications for specific user are being deleted from database, when only one should be removed 如何使用 Lombok 在 Spring/JPA/Hibernate 中获取带有所有子实体和子实体的父实体 - How to get parent entity with all child entities and child entities of children in Spring/JPA/Hibernate with Lombok 如何使JPA实体持久/删除但未提交? - How to get JPA entities persisted/removed but not committed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM