Search code examples
hibernatehibernate-envers

Why Envers creates one audit table per table


Envers expects one audit table for each auditable table in the system. So if I want to audit 30 table, I must have 30 audit tables. From Can i use only one table for all hibernate envers auditing? and from the docs, this seems to be the only option available.

I would like to know why this decision was made instead of having only one table with metadata that stores the entire audit information, or why this option was not provided:

1- Is that a question of performance?

2- Is there some scenario that cannot be covered having only one table for all audit info?

3- It was just the easiest way to implement it?

4- Other?


Solution

  • Two main reasons I think:

    • I wanted the audit tables to have a clear, human-browsable representation. While it is possible to understand and query the audit tables that Envers generates directly from SQL, it would be much harder for a human to comprehend a single table with data from all other tables.

    • a single table could become very large quickly, making it harder to manage audits of individual entities. With separate entities, the situation is clear

    Apart from that, I think both solutions might be good, but in the end you have to settle on one.

    It would be possible to implement Envers's functionality using a single table (a different audit strategy), but nobody did it yet.