fatherazrael
fatherazrael

Reputation: 5977

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)

Upvotes: 1

Views: 3216

Answers (3)

wallenborn
wallenborn

Reputation: 4273

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

Upvotes: 2

Tarun Jain
Tarun Jain

Reputation: 272

You can also use Spring AOP by writing a spring aspect before and after the execution of operation which will insert the data in audit tables

Upvotes: 0

nitika
nitika

Reputation: 303

You can Implement EmptyInterceptor of Hibernate. In methods of EmptyInterceptor you are able to find the field name, previous value and current value.

Upvotes: 3

Related Questions