Skip to content

Commit e8b46f6

Browse files
Spring Data JPA Auditing
1 parent 6c528c8 commit e8b46f6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

HibernateSpringBootAudit/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1+
**[Spring Data JPA Auditing](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootAudit)**
2+
3+
**Description:** Auditing is useful for maintaining history records. This can later help us in tracking user activities.
4+
5+
**Key points:**\
6+
- create an abstract base entity (e.g., `BaseEntity`) and annotate it with `@MappedSuperclass` and `@EntityListeners({AuditingEntityListener.class})`\
7+
- in this base entity, add the following fields that will be automatically persisted: `@CreatedDate protected LocalDateTime createdAt;`, `@LastModifiedDate protected LocalDateTime updatedAt;`, `@CreatedBy protected U createdBy;` and `@LastModifiedBy protected U modifiedBy;`\
8+
- enable auditing via `@EnableJpaAuditing(auditorAwareRef = "auditorAware")`\
9+
- provide an implementation for `AuditorAware` (this is needed for persisting the user that performed the modification; use Spring Security to return the currently logged-in user)\
10+
- expose this implementation via `@Bean`\
11+
- entites that should be audited should extend the base entity
12+
13+
-------------------------------
14+
15+
**You may like to try as well:**
16+
<a href="https://leanpub.com/java-persistence-performance-illustrated-guide"><p align="center"><img src="https://github.com/AnghelLeonard/Hibernate-SpringBoot/blob/master/Java%20Persistence%20Performance%20Illustrated%20Guide.jpg" height="410" width="350"/></p></a>
17+
118

0 commit comments

Comments
 (0)