Javers - What are advantages of using Javers instead of Envers?

8.9k views Asked by At

I am developing a RESTful API using Spring Data REST. Now for auditing, Spring does have the option to auditing meta data like created_date and modified_date but they don't provide entity versioning.

Currently there are two popular libraries for entity version which are Envers and Javers. I have looked over for a comparison of both but there arent any articles on this matter.

So what are the benefits and drawbacks of using Javers over Envers?

2

There are 2 answers

5
Bartek Walacik On BEST ANSWER

There are two big difference between JaVers and Envers:

  1. Envers is the Hibernate plugin. It has good integration with Hibernate but you can use it only with traditional SQL databases. If you choosed NoSQL database or SQL but with other persistence framework like JOOQ — Envers is not an option.

    On the contrary, JaVers can be used with any kind of database and any kind of persistence framework. For now, JaVers comes with repository implementations for MongoDB and popular SQL databases. Other databases (like Cassandra, Elastic) might be added in the future.

  2. Envers’ audit data model is a copy of application’s data model. As the doc says: For each audited entity, an audit table is created. By default, the audit table name is created by adding a _AUD suffix to the original name. It can be advantage, you have audit data close to your live data. Envers’ tables look familiar. It’s easy to query them with SQL.

    JaVers uses its own Snapshot model for audit data. Snapshots are decoupled from live data, JaVers saves them to the single table (jv_snapshots) as JSON documents with unified structure. Advantages? You can choose where to store audit data. By default JaVers uses the same database as application does, but you can point another database. For example, SQL for application and MongoDB for JaVers or centralized JaVers database shared for all applications in your company).

Read this blogpost with full JaVers vs Envers comparison: https://javers.org/blog/2017/12/javers-vs-envers-comparision.html

1
Peter Rader On

Enver is like git for a database.

I do not know Javers but a complete Envers databinding has this advantages:

  1. A table is created in the database called REVINFO having a timestamp and a PK.
  2. To every entity that is audited, one shadow-copy is created. Theese shadow-copies have every field nullable and the PK is not a PK. Theese shadow-copies have a new field, the reference to the table REVINFO.

This gives Enver the possibility to record changes that has been made in the past in this shadow-copies. You can move that shadow-tables into an different database.