Skip to content

Update auditing documentation. #2285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/main/asciidoc/auditing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
[[auditing.basics]]
== Basics
Spring Data provides sophisticated support to transparently keep track of who created or changed an entity and when the change happened. To benefit from that functionality, you have to equip your entity classes with auditing metadata that can be defined either using annotations or by implementing an interface.
Additionally auditing has to be enabled either via Java or XML configuration which ensures required infrastructure components get registered.
Please refer to the store specific section for configuration samples.

[NOTE]
====
Applications that only track creation and modification dates do not need to specify an <<auditing.auditor-aware>>.
====

[[auditing.annotations]]
=== Annotation-based Auditing Metadata
Expand All @@ -19,7 +26,7 @@ class Customer {
private User user;

@CreatedDate
private DateTime createdDate;
private Instant createdDate;

// … further properties omitted
}
Expand All @@ -28,6 +35,32 @@ class Customer {

As you can see, the annotations can be applied selectively, depending on which information you want to capture. The annotations capturing when changes were made can be used on properties of type Joda-Time, `DateTime`, legacy Java `Date` and `Calendar`, JDK8 date and time types, and `long` or `Long`.

Auditing metadata does not necessarily need to live in the root level entity but can be added to an embedded one (depending on the actual store in use), as shown in the snipped below.

.Audit metadata in embedded entity
====
[source, java]
----
class Customer {

@Embedded
private AuditMetadata auditingMetadata;

// … further properties omitted
}

class AuditMetadata {

@CreatedBy
private User user;

@CreatedDate
private Instant createdDate;

}
----
====

[[auditing.interfaces]]
=== Interface-based Auditing Metadata
In case you do not want to use annotations to define auditing metadata, you can let your domain class implement the `Auditable` interface. It exposes setter methods for all of the auditing properties.
Expand Down