Skip to content

Commit 1227e43

Browse files
christophstroblmp911de
authored andcommitted
Update auditing documentation.
Mention that even when only using the CreatedDate & LastModifiedDate annotations it is mandatory to enable auditing. Add sample of using auditing metadata within an embedded entity. Closes #2283 Original pull request: #2285
1 parent 6fe2c3a commit 1227e43

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

Diff for: src/main/asciidoc/auditing.adoc

+34-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
[[auditing.basics]]
55
== Basics
66
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.
7+
Additionally auditing has to be enabled either via Java or XML configuration which ensures required infrastructure components get registered.
8+
Please refer to the store specific section for configuration samples.
9+
10+
[NOTE]
11+
====
12+
Applications that only track creation and modification dates do not need to specify an <<auditing.auditor-aware>>.
13+
====
714

815
[[auditing.annotations]]
916
=== Annotation-based Auditing Metadata
@@ -19,7 +26,7 @@ class Customer {
1926
private User user;
2027
2128
@CreatedDate
22-
private DateTime createdDate;
29+
private Instant createdDate;
2330
2431
// … further properties omitted
2532
}
@@ -28,6 +35,32 @@ class Customer {
2835

2936
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`.
3037

38+
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.
39+
40+
.Audit metadata in embedded entity
41+
====
42+
[source, java]
43+
----
44+
class Customer {
45+
46+
@Embedded
47+
private AuditMetadata auditingMetadata;
48+
49+
// … further properties omitted
50+
}
51+
52+
class AuditMetadata {
53+
54+
@CreatedBy
55+
private User user;
56+
57+
@CreatedDate
58+
private Instant createdDate;
59+
60+
}
61+
----
62+
====
63+
3164
[[auditing.interfaces]]
3265
=== Interface-based Auditing Metadata
3366
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.

0 commit comments

Comments
 (0)