简体   繁体   English

Java,Hibernate,如何设置Envers,以便仅更改一个字段就不会创建新版本?

[英]Java, Hibernate, How to set Envers, so it won't create new versions if only one one field changed?

As in the title. 如标题中所示。 I have an entity with lot of fields, but every time this entity is saved to data base, envers creates another version event if the only thing that changed is "modificationTimestamp". 我有一个具有很多字段的实体,但是每次更改的唯一实体是“ modificationTimestamp”,则每次将该实体保存到数据库时,envers都会创建另一个版本事件。 Is there any way to ignore that one field? 有什么办法可以忽略这一领域? But it also need to be written into db if any other field changes. 但是,如果其他任何字段发生更改,也需要将其写入db。

The easiest way would be to added the @NotAudited annotation to that property in your model. 最简单的方法是将@NotAudited批注添加到模型中的该属性。 This means that field will no longer be used in the delta comparison to determine if the entity was modified and thus will no longer trigger an audit row to be added. 这意味着在增量比较中将不再使用该字段来确定是否已修改实体,因此将不再触发要添加的审计行。

This also means you'll have a small inconsistency in your audit data because entries added prior will contain a value in this modificationTimestamp column where-as rows after adding the annotation will begin to contain null values because Envers no longer tracks this column. 这也意味着你必须在你的审计数据一个小矛盾,因为将包含在这个值前项添加modificationTimestamp的列,其中,作为行添加注释后,将开始包含值,因为Envers不再跟踪此列。

If you don't need the values in the older rows, you can safely drop the column manually from the audit schema if its a value that is of no importance from an audit history perspective. 如果您不需要旧行中的值,则可以安全地从审计模式中手动删除该列,如果该列的值从审计历史记录的角度来看并不重要。

If you need the older values but the audit schema column was created with a not-null constraint in someway, you may need to alter the schema manually and allow it to insert null values simply due to the change in the behavior. 如果您需要较旧的值,但审计模式列是在某种程度上使用非空约束创建的,则可能仅由于行为更改而需要手动更改模式,并允许其插入空值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM