Envers @OneToMany 对 CREATE(0) 进行审计,但不对 DELETE(2) 进行审计
我看过很多类似的问题,例如: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里挖一个旧的,但我想我知道答案,但这只是因为我这个周末遇到了同样的问题。
你在做什么:
或者你在做什么:
第一个应该给你一个 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:
Or are you doing:
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?