Envers 多级实体修订指南
用户有 n 个联系人。联系人可以有本地化的评论(评论在联系人之间共享)。 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级更改”,因为用户和联系人之间的关系没有改变,只有联系人评论中的德语字符串发生了变化。
但我想在用户历史记录中看到一个新条目(更改了联系人 XYZ 的德语评论)。
我该怎么做? :D
谢谢
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;
}
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.
But I want see in the User History a new Entry (Changed german comment for contact XYZ).
How can I do this? :D
Thxs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许一个想法是使用自定义修订日志(http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/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.