简体   繁体   English

如何在Hibernate中创建Audit Log Trail?

[英]How to create Audit Log Trail in Hibernate?

Following is Table Structure: 以下是表结构:

id | createdby | createddate | tablename | columnname | primaryid | oldavalue | newvalue | remarks

we get delimited file in which we have some values to update in 4 tables. 我们得到定界文件,其中有一些值需要在4个表中更新。 Four tables have 10 Columns each. 四个表各有10列。 We do not know what to update. 我们不知道要更新什么。 So we just update whole row against one Primary ID. 因此,我们只针对一个主要ID更新整行。

Now Challenges here are: 现在的挑战是:

  1. How to get Table Name, Column Name in Hibernate? 如何在Hibernate中获取表名,列名?

  2. How to fetch Old Value; 如何获取旧价值; during an update? 在更新期间? How to know which field we are updating has old value and we are now inserting new value? 如何知道我们要更新的字段具有旧值,现在我们要插入新值? (We don't compared fields yet) (我们尚未比较字段)

You can Implement EmptyInterceptor of Hibernate. 您可以实现Hibernate的EmptyInterceptor。 In methods of EmptyInterceptor you are able to find the field name, previous value and current value. 在EmptyInterceptor的方法中,您可以找到字段名称,先前值和当前值。

My favorite tool for this is Hibernate Envers . 我最喜欢的工具是Hibernate Envers You just annotate your entities as @Audited and envers takes care of the interceptors. 您只需将实体注释为@Audited,然后envers会处理拦截器。

您还可以通过在执行操作之前和之后编写spring方面来使用Spring AOP,该方面将在审计表中插入数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM