@AuditOverride is not a JPA or Spring Data annotation. It belongs to Hibernate Envers, the library that keeps a revision history of entities, and it controls which inherited or embedded properties are included in that history. You use it to switch auditing on or off for properties that come from a superclass, without changing the superclass itself.
It has nothing to do with the Spring Data fields @CreatedDate and @LastModifiedDate. Those fill timestamps on the current row. Envers audit tables record every past version of a row.
The word "audit" covers two separate features, and mixing them up is the usual source of confusion.
| Feature | Library | Annotations | What it stores |
|---|---|---|---|
| Auditing fields | Spring Data JPA | @CreatedDate, @LastModifiedDate, @CreatedBy, @LastModifiedBy, @EnableJpaAuditing | Who and when for the current row only |
| Revision history | Hibernate Envers | @Audited, @NotAudited, @AuditOverride | Every historical version in _aud tables |
@AuditOverride lives in org.hibernate.envers. It cannot rename a column. Renaming a column is done with @AttributeOverride from JPA.
When you mark an entity with @Audited, Envers audits the properties declared on that entity. Properties inherited from a @MappedSuperclass are audited only if that superclass is itself @Audited. If you cannot or do not want to annotate the superclass, @AuditOverride tells Envers how to treat it from the entity.
Its main elements are:
forClass: the superclass or embeddable class whose properties you are configuring.isAudited: true to audit them (the default), false to exclude them.name: limit the override to one property. If omitted, it covers the whole class.@AuditOverrides groups several of them, and the annotation is repeatable in current Envers versions.
Suppose a shared base class is used by many entities and carries no Envers annotations:
One entity wants its inherited fields in the revision history:
Envers now writes created_at and created_by to the invoice_aud table together with number. Another entity that extends BaseEntity without the override keeps those fields out of its history.
Setting isAudited = false with a name removes a single property from the history even when the rest is audited:
Here createdAt is audited and createdBy is not. On older Envers versions that do not allow repeating the annotation, group the two inside @AuditOverrides({ ... }).
The two features work side by side. A common setup is a base class with Spring Data fields and an entity that keeps their history in Envers:
Enable the Spring Data side once with @EnableJpaAuditing on a configuration class. Then add @Audited and @AuditOverride(forClass = Auditable.class) to any entity that should also record the history of createdDate and lastModifiedDate.
No. It is a Hibernate Envers annotation in org.hibernate.envers. Plain JPA has no revision history feature.
No. It only decides whether a property is included in the history. Use @AttributeOverride for column names.
@NotAudited is placed on a property you own. @AuditOverride works from the entity and configures properties that come from a superclass or embeddable you do not want to edit.
Yes. @AuditOverride adjusts how Envers treats inherited properties, but the entity itself still has to be audited.
@AuditOverride is an Hibernate Envers tool for including or excluding inherited and embedded properties in the revision history of an audited entity. Keep it separate in your mind from Spring Data auditing fields, and use @AttributeOverride when the goal is to change a column name.