Envers 与 Hibernate 拦截器,onDelete

发布于 2024-12-07 16:06:04 字数 512 浏览 0 评论 0原文

我正在尝试实现一个简单的基于 Envers + 拦截器的方法来审计我的 Hibernate 实体。为此,按照典型方法,有一个包含所有审核属性的 BaseEntity

BaseEntity{
    createdOn;
    createdBy;
    updatedOn;
    updatedBy;
}

AuditInterceptor 中,我重写了 onFlushDirty>onSave 方法来操作上述属性,具体取决于它是实体保存还是更新。保存和更新一切都按预期进行。

我面临的问题是:我还需要一种方法来操作删除操作的上述属性。覆盖 onDelete 确实为我提供了 state[] 数组的句柄,但修改它不会反映在 _AUD(审核)表中。简而言之:我也希望能够审核审计表中的删除操作。

有没有解决方法,或者我错过了什么?

I'm trying to implement a simple Envers + interceptor based approach to audit my Hibernate entities. For this, as per the typical approach, there's a BaseEntity with all the audit properties:

BaseEntity{
    createdOn;
    createdBy;
    updatedOn;
    updatedBy;
}

In the AuditInterceptor, I have overridden onFlushDirty and onSave methods to manipulate the above properties depending upon whether it's an entity Save or Update. Everything works as expected for Save and Update.

The issue that I'm facing is: I need a way to be able to manipulate the above properties for Delete operations as well. Overriding onDelete does give me a handle to the state[] array, but modifying it doesn't reflect in the _AUD (audit) tables. In a nutshell: I want to be able to audit delete operations in the audit tables as well.

Is there a workaround for this, or am I missing something?

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

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

发布评论

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

评论(1

欲拥i 2024-12-14 16:06:04

我认为您不需要实现 onSave、onFlushDirty 方法。

您只需要实现 RevisionListener 接口即可。如果您遵循此处的模式,您也不需要将这些属性(createdOn 等)添加到您的实体中(除非您需要它们进行正常操作)。

请参阅http://docs.jboss.org/hibernate /envers/3.6/reference/en-US/html_single/#revisionlog 了解更多详细信息。在此示例中,他们使用 Seam 来获取登录用户。

Envers 允许您将审核与实体分开,从而保持正常模型的整洁并最大限度地减少审核所需的代码。

I don't think you need to implement the onSave, onFlushDirty methods.

You just need to implement the RevisionListener interface. If you follow the pattern here you don't need to add those properties (createdOn etc) to your entities either (unless you need them for normal operations).

See http://docs.jboss.org/hibernate/envers/3.6/reference/en-US/html_single/#revisionlog for more details. In the example here they are using Seam to get the logged in user.

Envers allow you to separate your auditing from your entities which keeps your normal model clean and minimises the code required to do the auditing.

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