问题描述
我正在使用Spring Data REST开发RESTful API。现在,对于审核,Spring确实可以选择审核元数据,例如 created_date
和 modified_date
,但它们不提供实体
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.
当前,有两个流行的实体版本库是Envers和Javers。我一直在寻找两者的比较,但是对此问题没有任何文章。
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.
那么使用Javers over Envers有什么优点和缺点?
So what are the benefits and drawbacks of using Javers over Envers?
推荐答案
JaVers和Envers有两个大区别:
There are two big difference between JaVers and Envers:
-
Envers是Hibernate插件。
它与Hibernate集成良好,但您只能将其与传统SQL数据库一起使用。
如果您选择NoSQL数据库或SQL但使用其他持久性框架,例如
&mdash ;不能选择Envers。
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 likeJOOQ — Envers is not an option.
相反,JaVers可以与任何类型的数据库和任何类型的
持久性框架一起使用。目前,JaVers随附了MongoDB和
流行SQL数据库的存储库实现。将来可能会添加其他数据库(如Cassandra,Elastic)。
On the contrary, JaVers can be used with any kind of database and any kind ofpersistence framework. For now, JaVers comes with repository implementations for MongoDB andpopular SQL databases. Other databases (like Cassandra, Elastic) might be added in the future.
Envers的审核数据模型是应用程序数据模型的副本。正如文档所说:
为每个被审计实体创建一个审计表。
默认情况下,审核表名称是通过在原始名称后添加 _AUD
后缀来创建的。
审核数据接近您的实时数据。 Envers的表格看起来很熟悉。
可以很容易地用SQL查询它们。
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使用自己的快照模型来存储审计数据。
快照是与实时数据分离的,
JaVers将它们作为具有统一结构的JSON文档保存到单个表( jv_snapshots
)中。
的优势?您可以选择存储审核数据的位置。
默认情况下,JaVers使用与应用程序相同的数据库
,但是您可以指向另一个数据库。例如,用于应用程序的SQL和用于JaVers
的MongoDB或为公司中所有应用程序共享的集中式JaVers数据库)。
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 JaVersor centralized JaVers database shared for all applications in your company).
阅读此博客文章,并提供完整的JaVers与Envers比较:
Read this blogpost with full JaVers vs Envers comparison:https://javers.org/blog/2017/12/javers-vs-envers-comparision.html
这篇关于Javers-使用Javers而不是Envers有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!