Envers 多级实体修订指南

发布于 2024-12-29 17:40:55 字数 855 浏览 3 评论 0原文

用户有 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 技术交流群。

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

发布评论

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

评论(1

苏别ゝ 2025-01-05 17:40:56

也许一个想法是使用自定义修订日志(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.

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