Javers - What are advantages of using Javers instead of Envers?
Asked Answered
B

2

12

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?

Blastocoel answered 6/9, 2017 at 13:51 Comment(1)
What about @Version. That is what we use for entity versioning in Spring Data JPA and Spring Data RESTUndertow
B
20

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

Bottleneck answered 7/9, 2017 at 7:0 Comment(5)
Thank you for the response. Looking forward to your article.Blastocoel
I just want to point out that you can also point Envers to a separate database or schema for the audit data storage if you don't want to use the same database or schema that Hibernate ORM uses.Formfitting
yes, separate schema can be set with org.hibernate.envers.default_schema but I cant find in the envers docs the option of changing database, could you please point it?Bottleneck
I didn't see an option to change the DB server, only the schema, on the same server.Chante
SqlRepositoryBuilder accepts connectionProvide which can provide a connection to any DB you wantBottleneck
B
-3

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.

Bungalow answered 6/9, 2017 at 14:46 Comment(1)
i dont think its like git. thats a wrong comparision. git only stores the difference whereas envers stores the a copy of the new version, so the methodology is different. I would say envers ensures that your data model's have a version control system.Corporate

© 2022 - 2024 — McMap. All rights reserved.