Annotation 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 @Changelog entity 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 ChangesetIdentifierSupplier may be specified via the configuration property "hibernate.temporal.changeset_id_supplier".
If neither is provided, the current JVM instant is used as the changeset identifier, but relying on this default behavior is not recommended.

To query the audit log:

  • use atChangeset() when opening a session to transparently read entity state as of a specific changeset,
  • use AuditLog for programmatic access to revision history, modification types, and cross-entity queries, or
  • open a session with ALL_CHANGESETS and write custom HQL queries using the changesetId() and modificationType() 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: