Auditing with Hibernate Envers and Spring Data JPA
In this example you can see how to use Envers for Auditing your tables.
17.x
e.g.: sdk install java 17.0.9-amznsdk install java 17.0.9-amzn
8.x
e.g. you can use the embedded wrapper gradlew
or install sdk install gradle 8.5
26.x
8.2.x
. Check the Docker sectionThis is based on Spring Boot Application 3.2.1
, and it is configured with mysql database.
There are the following entities:
For each table (entity) the framework will create the auditory tables.
docker run --name mysql-db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=jcalvopinam -d mysql:8.2.0
docker start mysql-db
docker stop mysql-db
Since the current version, it is not necessary create manually the schema,
when the application startup, it will create the schema and the entities.
Anyway you can find the script in src/main/resources/db/scripts/database.sql
as well as the script with the DDL of
tables tables.sql
Compile the project with the following command:
./gradlew clean build
src/main/java/com/jcalvopinam/SampleEnversApplication.java
or
./gradlew bootRun
I used the postman application as a client to test the endpoints, you can import the collection:
ll src/main/resources/endpoints/collection\[postmanv2.1\].json
Or if you prefer, you can look at the Controllers inside of com.jcalvopinam.web
package and the DTOs inside of com.jcalvopinam.dto