From 7cba94261e336d7c4c8d27f848c5654b3a7215c0 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 30 Jan 2013 15:09:57 +0100 Subject: [PATCH] DATACMNS-277 - Include general auditing documentation from Spring Data Commons. --- src/docbkx/reference/jpa.xml | 54 ++++++------------------------------ 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/src/docbkx/reference/jpa.xml b/src/docbkx/reference/jpa.xml index 7d0771386..f389067c9 100644 --- a/src/docbkx/reference/jpa.xml +++ b/src/docbkx/reference/jpa.xml @@ -1,7 +1,7 @@ - + JPA Repositories @@ -885,52 +885,14 @@ public interface UserRepository extends JpaRepository<User, Long> {
+ Auditing + + + + - Most applications will require some form of auditability to track - when an entity was created or modified and by whom. Spring Data JPA - provides facilities to add this audit information to an entity - transparently by AOP means. To take part in this functionality your domain - classes must implement a more advanced interface: - - - <interfacename>Auditable</interfacename> interface - - public interface Auditable<U, ID extends Serializable> - extends Persistable<ID> { - - U getCreatedBy(); - - void setCreatedBy(U createdBy); - - DateTime getCreatedDate(); - - void setCreated(Date creationDate); - - U getLastModifiedBy(); - - void setLastModifiedBy(U lastModifiedBy); - - DateTime getLastModifiedDate(); - - void setLastModified(Date lastModifiedDate); -} - - - As you can see the modifying entity itself only has to be an entity. - Mostly this will be some sort of User entity, so we chose U as parameter - type. - - - To minimize boilerplate code Spring Data JPA offers - AbstractPersistable and - AbstractAuditable base classes that implement and - pre-configure entities. Thus you can decide to only implement the - interface or enjoy more sophisticated support by extending the base - class. - - - +
General auditing configuration Spring Data JPA ships with an entity listener that can be used to @@ -978,7 +940,7 @@ public interface UserRepository extends JpaRepository<User, Long> { your application that tracks the user currently working with the system. This component should be AuditorAware and thus allow seamless tracking of the auditor. - +