Envers @OneToMany 对 CREATE(0) 进行审计,但不对 DELETE(2) 进行审计

发布于 2024-10-14 06:10:29 字数 2354 浏览 4 评论 0原文

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

一个活动有很多发生,当创建一个发生时,activity_occurrence_AUD 表会正确更新为 0(创建)修订版。

但是,当事件被删除时,activity_occurrence_AUD 表不会填充 2(删除)修订版。

活动实体:

@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" />

任何帮助将不胜感激。

奇怪的是,更新可以,但删除不行。

如果我可以提供更多信息,请告诉我。

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

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

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

Activity Entity:

@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;

....

}

hibernate properties:

<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" />

Any help would be much appreciated.

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

Let me know if I can provide any more information.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清音悠歌 2024-10-21 06:10:29

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

你在做什么:

Activity.getActivityOccurrenceList().remove(OCCURRENCE);

或者你在做什么:

Activity.setActivityOccurrenceList(NEW_LIST_EXLUDING_REMOVED_OCCURRENCE);

第一个应该给你一个 REVTYPE 为 2,而第二个选项可能会给你一个 REVTYPE 0。

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

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

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

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

Are you doing:

Activity.getActivityOccurrenceList().remove(OCCURRENCE);

Or are you doing:

Activity.setActivityOccurrenceList(NEW_LIST_EXLUDING_REMOVED_OCCURRENCE);

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

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.

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文