启用多层次实体修订方法 [英] envers multi level entity revision howto
问题描述
用户有n个联系人.联系人可以具有本地化的注释(注释在联系人之间共享). Java Bean:
User have n Contacts. A Contact can have a localized Comment (Comments are shared between Contacts). Java Beans:
@Audited
@Entity
public class User {
@OneToMany(fetch = FetchType.EAGER,
cascade = CascadeType.ALL,
orphanRemoval = true)
Set<Context> contacts;
}
@Audited
@Entity
public class Contact {
@ManyToOne(fetch = FetchType.EAGER,
cascade = {
CascadeType.MERGE,
CascadeType.PERSIST,
CascadeType.REFRESH})
Comment comment;
}
@Audited
@Entity
public class Comment {
String de;
String en;
String fr;
}
如果我更改了联系人(Contact.comment)的德语本地化(Comment.de),则将创建一个新修订,但不适用于用户.如果我向envers请求用户修订,因为用户和联系人之间的关系没有更改,我将永远不会看到此级别2更改",只有联系人注释中的德语字符串发生了更改.
If I change the german localization (Comment.de) of a contact (Contact.comment) then this will create a new revision but not for User. If I ask envers for User Revisions I will never see this "Level 2 change" because the relation between User and Contact was not change, only the german string in the Contact Comment was changed.
但是我想在用户历史记录中看到一个新条目(联系人XYZ的德语注释已更改).
But I want see in the User History a new Entry (Changed german comment for contact XYZ).
我该怎么做? :D
Thxs
推荐答案
也许一个想法是使用自定义修订日志(http://docs.jboss.org/hibernate/orm/4.1/devguide/zh-CN /html/ch15.html#envers-revisionlog)中存储与更改相关的根"实体.这可能不是最有效,但是取决于您的域模型,这可能就是您想要的.
Maybe an idea would be to use a custom revision log (http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch15.html#envers-revisionlog) in which you store the "root" entity/entities for which the change is relevant. This may not be the most efficient but depending on your domain model, this may be what you want.
这篇关于启用多层次实体修订方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!