Better approach to maintain audit of few entities
-
14-07-2021 - |
Question
I have one Hibernate entity with following structure:
@Entity
public class A
{
private Integer id;
private String name;
@OneToMany
private List<B> bList;
}
@Entity
public class B
{
private Integer id;
@OneToMany
private List<C> cList;
}
Now I wants to maintain history on entity "A", with information like :
historyDate | fieldsChanged | updatedBy | createdBy
In fieldsChanged
column i want the name of the columns of entity A and if any changes applied in entity B or C.
Now I have googled and find few of the following ways to achieve these :
- Writer trigger on the DB
- Own Java logic to maintain history table
- Using Hibernate Envers
Now I am not sure what should be the better approach from above or anything else.
Any suggestion would be highly appreciated...
Solution
Envers uses a different auditing scheme - storing the full content of an entity for each change. The answer really depends on what you need.
- is the right choice if the DB is accessed directly from various systems, written in various languages.
- is best if you need to have the structure that you wrote about
- gives you auditing, but in a different format.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow