Search code examples
springspring-data-resthibernate-enversauditingjavers

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


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?


Solution

  • 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