如何检索经过审计的关系修订? [英] How to retrieve the audited revision of relations?

查看:109
本文介绍了如何检索经过审计的关系修订?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的用例



我有两个实体:Personn和Email(@OneToMany关系)。首先我创建一个新的Personn,带有一个Email(=>两者都有修订版本1),然后我修改Email(= >电子邮件有一个修订2,但Personn只有一个修订版本1)



在Web应用程序中,最终用户只有一个视图来显示Personn的属性,他的电子邮件属性。在这个视图中,我想显示此Personn的所有现有修订。但是,当我查询审计系统时,它不会显示修订版2,因为Personn尚未修改。



我了解技术问题,但在最终版本中,用户的观点,他想看到一个修订版本2,因为他修改了人物的电子邮件!他不知道(也不必知道)我们决定将这些信息分成两个Java对象。当然,这个问题不仅仅是Personn-Email关系(我在Personn和在同一视图中显示的其他对象之间有很多关系--Adress,Job,Site,Card等等)



我想到了两种解决方案:

1-查询所有关系以确定修订版是否存在(但我想它会生成一个大的请求或多个请求 - 我有很多关系)。



2-设置hibernate.listeners.envers.autoRegister为false,写我自己的EnversIntegrator和事件实现。在事件实现中(它覆盖默认的Envers实现),当电子邮件的属性被修改时,我将为Personn创建一个ModWorkUnit(它当然不会被硬编码:在personn字段上使用@AuditedPropagation的自定义注释)。
这个解决方案的缺陷是为Personn创建很多行,即使它没有被修改。

您如何看待这些解决方案?你知道更好的方法来解决这种用例吗?



感谢您的建议。

解决方案

我一直无法使自定义后更新侦听器解决方案工作。 addCollectionChangeWorkUnit似乎不存在,直到休眠4.1它标记为私有。 EnversPostUpdateEventListenerImpl似乎出现在hibernate 4.0中的某个时刻。



我通过在您的A实体的等价物上添加隐藏的lastUpdated日期字段来解决我的问题。
$ b

  @Entity 
公共类A {
私人日期lastModified;
@OneToMany(mappedBy =a,cascade = CascadeType.ALL)
private List< B> blist;
public void touch(){
lastModified = new Date();






$ p $在相关实体(如你B字段)中,我添加了以下内容:

  public class B {
@ManyToOne
private A a;

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



$ / code $ / pre>

这可确保修订是只要将修订添加到B即使它需要许多实体中的自定义代码,也会添加到A中。


Here is my use case

I have two entities : Personn and Email (a @OneToMany relation). Both of them are audited.

First I create a new Personn, with an Email (=> Both of them have a revision 1), then I modify the Email (=> The Email has a revision 2, but Personn has only a revision 1)

In the web application the end-user has only one view to show the Personn's attributs and also his Emails attributs. In this view I want to show all existing revisions for this Personn. But when I query the audit system, it doesn't show me revision 2 as the Personn has not been modified.

I understand the technical problem, but in the end-user point of view, he wants to see a revision 2 because he modified the personn's email ! He doesn't know (and doesn't have to know) that we deciced to divide these information into 2 Java objects. Of course this problem is not only for Personn-Email relation (I've got a lot of relation between Personn and other objects which are shown in the same view - Adress, Job, Site, Card, and many more)

I thought about 2 solutions:

1- Querying all relations to know if a Revision exist (but I suppose it will generate a big request or multiple requests - I've got a lot of relations).

2- Setting "hibernate.listeners.envers.autoRegister" to false, writing my own EnversIntegrator and event implementations. In event implementations (which override default Envers implementations), I will create a ModWorkUnit for Personn when Email's attributs have been modified (it will not been hard coded of course: perharps a custom annotation like @AuditedPropagation on the personn field). The flaw of this solution is to create a lot a row for Personn even if it was not modified.

What do you think about these solutions ? Do you know a better way to solve that kind of use-case ?

Thanks for your advices.

解决方案

I have been unable to make the custom post update listener solution work. addCollectionChangeWorkUnit doesn't seem to exist until hibernate 4.1 where it is marked private. EnversPostUpdateEventListenerImpl seems to appear at some point in hibernate 4.0

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 even though it requires custom code in many entities.

这篇关于如何检索经过审计的关系修订?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆