Annotation Interface Audited
@Documented
@Target({PACKAGE,TYPE,FIELD,METHOD,ANNOTATION_TYPE})
@Retention(RUNTIME)
@Incubating
public @interface Audited
Specifies that the annotated entity class is an audited entity
or audited collection. An audited entity or collection keeps
a historical record of changes over time. Unlike a
temporal entity, it explicitly records
the nature of each change, such as creation, modification, or
deletion, and associates each change with a changeset.
An audited entity or collection maps to two tables, a table
holding the current state of the entity or collection, and an
audit log table with a record of each change.
The audit log contains the following columns:
- columns holding the state of the entity or collection at the moment of creation, modification, or deletion, except for state held by excluded attributes,
- a changeset id recording the changeset in which the change occurred, and
- a column indicating the type of change, encoded as 0 for creation, 1 for modification, and 2 for deletion.
Each changeset is identified by a unique, monotonically increasing changeset id. Changeset ids can be supplied in two ways:
- A
@Changelogentity may be defined in the domain model. A new instance is automatically persisted once per transaction, and its generated primary key serves as the changeset id. A changelog entity also carries metadata such as its creation timestamp and, optionally, additional information such as the current user or a comment. - A custom
ChangesetIdentifierSuppliermay be specified via the configuration property "hibernate.temporal.changeset_id_supplier".
To query the audit log:
- use
atChangeset()when opening a session to transparently read entity state as of a specific changeset, - use
AuditLogfor programmatic access to revision history, modification types, and cross-entity queries, or - open a session with
ALL_CHANGESETSand write custom HQL queries using thechangesetId()andmodificationType()functions.
Use the nested @Audited.Table annotation to
customize the audit log's table name, schema, catalog, or
column names for the audit log.
- Since:
- 7.4
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceSpecifies a custom audit table name (and optionally schema and catalog) for an audited collection.static @interfaceExcludes the annotated attribute from auditing.static @interfaceSpecifies a custom audit table name for a@SecondaryTable.static @interfaceContainer for repeatableAudited.SecondaryTableannotations.static @interfaceSpecifies the audit log's table mapping for an audited entity.