jpa
How to implement auditing in Spring Data JPA?
- Enable Auditing: Add
@EnableJpaAuditingto your configuration class. - Add Annotations to Entity:
@Entity @EntityListeners(AuditingEntityListener.class) public class BaseEntity { @CreatedDate private LocalDateTime createdDate; @LastModifiedDate private LocalDateTime lastModifiedDate; @CreatedBy private String createdBy; }
- AuditorAware: Implement this interface to tell Spring who the "current user" is (usually from Spring Security context).