JDBC Auditing
Explore how to implement JDBC auditing in Spring Data JDBC to automatically track and record data changes. Understand how to configure auditing metadata in database schemas and POJOs, use annotations like @CreatedBy and @LastModifiedDate, and set up an AuditorAware bean to capture user information for audit trails. Gain practical skills to maintain historical records of data modifications in your Spring Boot application.
JDBC auditing is a feature in which changes to data stored in a database are automatically tracked and recorded. It helps maintain an audit trail by capturing details such as who made the change and when it occurred, providing a historical record of data modifications by using properties like createdBy, (the user/system that adds the data), createdAt (the date and time when the data is added), updatedBy (the user/system that updates the data), and updatedAt (the date and time when the data is updated).
Spring Data JDBC provides a sophisticated way of adding auditing features to the Spring Boot project. Let’s explore it.
Database schema setup
First, let’s modify our database schema in the schema.sql file to add metadata columns that track changes made to the data. So, we add columns like created_by, created_at, updated_by ...