对CREATE(0)启用@OneToMany审核,但对DELETE(2)不启用 [英] Envers @OneToMany audit on CREATE(0) but not on DELETE(2)

查看:105
本文介绍了对CREATE(0)启用@OneToMany审核,但对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);

第一个选项的REVTYPE为2,而第二个选项的REVTYPE为0.

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?

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

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