Hibernate Envers : track revisions in the owning side of a OneToMany relation

僤鯓⒐⒋嵵緔 提交于 2019-12-02 02:12:22

I solved my problem by adding a hidden lastUpdated date field on my equivalent of your A entity.

@Entity
public class A {
    private Date lastModified;
    @OneToMany(mappedBy = "a", cascade = CascadeType.ALL )
    private List<B> blist;
    public void touch(){
        lastModified=new Date();
    }
}

In the related entities (like you B field), I added the following :

public class B {
    @ManyToOne
    private A a; 

    @PreUpdate
    public void ensureParentUpdated(){
        if(a!=null){
            a.touch();
        }
    }
}

This ensures that a revision is added to A whenever a revision is added to B.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!