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 :

  1. Writer trigger on the DB
  2. Own Java logic to maintain history table
  3. 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...

Was it helpful?

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.

  1. is the right choice if the DB is accessed directly from various systems, written in various languages.
  2. is best if you need to have the structure that you wrote about
  3. gives you auditing, but in a different format.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top