Envers @OneToMany 审计 CREATE(0) 但不审计 DELETE(2) [英] Envers @OneToMany audit on CREATE(0) but not on DELETE(2)

查看:29
本文介绍了Envers @OneToMany 审计 CREATE(0) 但不审计 DELETE(2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多类似的问题,例如:http://community.jboss.org/message/580407#580407 但还没有找到解决方案.

I've looked a quite a few similar issues like: http://community.jboss.org/message/580407#580407 but haven't found a solution yet.

一个活动有很多次出现,当创建一个出现时,activity_occurence_AUD 表会正确更新为 0(创建)修订版.

An Activity has many Occurences, when an occurence is created the activity_occurence_AUD table is updated correctly with a 0 (create) revision.

但是,当某个事件被删除时,activity_occurence_AUD 表不会填充 2(删除)修订版.

However when an occurance is removed the activity_occurence_AUD table is not populated with a 2 (delete) revision.

活动实体:

@Entity
@Table(name = "activity")
@Audited
public class Activity implements Serializable {
    private static final long serialVersionUID = 1L;

    public static final int[] VALID_PRIORITIES = { 0, 1, 2, 3 };

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Long id;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "activity")
    private List<ActivityOccurrence> activityOccurrenceList;

....

}

ActivityOccurence Entity:

@Entity
@Table(name = "activity_occurrence")
@Audited    
public class ActivityOccurrence implements Comparable<ActivityOccurrence>, Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Long id;

    @JoinColumn(name = "activity_id", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false)
    private Activity activity;

....

}

休眠属性:

<entry key="hibernate.ejb.event.post-insert"     
  value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" />
<entry key="hibernate.ejb.event.post-update"
  value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" />
<entry key="hibernate.ejb.event.post-delete"
  value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" />
<entry key="hibernate.ejb.event.pre-collection-update"
  value="org.hibernate.envers.event.AuditEventListener" />
<entry key="hibernate.ejb.event.pre-collection-remove"
  value="org.hibernate.envers.event.AuditEventListener" />
<entry key="hibernate.ejb.event.post-collection-recreate" 
  value="org.hibernate.envers.event.AuditEventListener" />

任何帮助将不胜感激.

奇怪的是,更新有效,但删除无效.

It's strange that the update works but the delete doesn't.

如果我能提供更多信息,请告诉我.

Let me know if I can provide any more information.

推荐答案

在这里挖掘一个旧的,但我想我知道答案,但只是因为我这个周末遇到了同样的问题.

Digging up an old one here but think I know the answer, but only because I have run into the same problem this weekend.

你在做什么:

Activity.getActivityOccurrenceList().remove(OCCURRENCE);

或者你在做什么:

Activity.setActivityOccurrenceList(NEW_LIST_EXLUDING_REMOVED_OCCURRENCE);

第一个选项应该为您提供 2 的 REVTYPE,而第二个选项可能会给您 0 的 REVTYPE.

The first should give you a REVTYPE of 2, whereas the second option will probably give you a REVTYPE of 0.

当然我可能是错的,因为我的例子是 ManyToMany 并且有一个连接表,但根据我的修补,这就是我认为它的工作方式.

Of course I could be wrong, because my example is ManyToMany and has a join table but from my tinkering this is how I think it's working.

就我而言,但使用您的示例;spring 正在投标活动发生的列表,并且 spring 每次都会创建一个新列表来执行此操作,即使我实际上删除了一个事件,也会导致 REVTYPE 为 0 (ADD).

In my case, but using your example; spring is biding the list of activity occurrences, and spring creates a new list each time to do this, resulting in the REVTYPE of 0 (ADD) even though I actually removed an occurrence.

您最终自己找到了解决方案吗?如果有,可以分享一下吗?

Did you eventually find a solution to this yourself? If so could you share?

这篇关于Envers @OneToMany 审计 CREATE(0) 但不审计 DELETE(2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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