简体   繁体   中英

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. Four tables have 10 Columns each. We do not know what to update. So we just update whole row against one Primary ID.

Now Challenges here are:

  1. How to get Table Name, Column Name in 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. In methods of EmptyInterceptor you are able to find the field name, previous value and current value.

My favorite tool for this is Hibernate Envers . You just annotate your entities as @Audited and envers takes care of the interceptors.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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