简体   繁体   中英

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". Is there any way to ignore that one field? But it also need to be written into db if any other field changes.

The easiest way would be to added the @NotAudited annotation to that property in your model. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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