my-spring-boot-experiments
  • README
  • Spring Batch implementation
  • API Example for Archunit
  • spring-boot-chaos-monkey
  • Grafana LGTM Implementation
  • MongoDb for insertion and search using elastic search
  • OpenSearch Implementation
  • spring-boot-rabbitmq-thymeleaf
  • boot-rest-docs-sample
  • boot-strategy-plugin
  • spring-boot-togglz-sample
  • spring-boot-ultimate-redis
  • GraphQL
    • spring-boot-graphql-querydsl
    • GraphQl implementation using webflux
    • GraphQl implementation using webmvc
  • httpClients
    • http-proxy
    • rest-template
    • rest-client
    • web-client-mvc
    • web-client-webflux
  • jmh-benchmark
  • jpa
    • Custom Sequence
    • Hibernate Envers Implementation
    • multiple datasources using Spring Boot
    • spring-boot-hibernate2ndlevelcache-sample
    • JNDI in embedded Tomcat
    • JPA Jooq Marriage
    • JPA locks implementation
    • read-replica-with-spring-boot
    • KeySet Pagination Using Blaze
    • KeySet Pagination Using Data-JPA
    • MultiTenancy using Hibernate in Spring Data JPA
      • multitenancy-db
      • multidatasource-multitenancy
      • Partitioned (Discriminator) Data – the data for each tenant is partitioned by a discriminator value
      • schema
  • open-api-spring-boot
  • r2dbc
    • r2dbc-jooq
    • PostgreSQL JSON and enum column support
    • PostgreSQL Notify and Listen support using reactive spring boot
    • r2dbc-boot
    • reactive-cache
  • scheduler
    • Scheduling using JobRunr
    • Scheduling using Quartz
    • Scheduling using Shedlock distribution
  • Code Of Conduct
Powered by GitBook
On this page
  • Why Use Envers?
  • Additional Notes
  • Format code
  • Run tests
  • Run locally
  • Using Testcontainers at Development Time
  • Useful Links
  • Update to Spring Boot 3
  • Reference:

Was this helpful?

Edit on GitHub
  1. jpa

Hibernate Envers Implementation

PreviousCustom SequenceNextmultiple datasources using Spring Boot

Last updated 4 months ago

Was this helpful?

Extends Spring Data JPA with to audit all changes to your entities automatically.

Why Use Envers?

  • Compliance & Audit: Track who changed what and when.

  • Version History: Revert or compare entity versions over time.

Spring Data Envers is a tool for auditing changes made to persistent entities in a Spring-based application. It allows developers to track and log changes made to entities over time, providing a historical view of the data. This can be useful for compliance and regulatory purposes, as well as for debugging and performance analysis. Spring Data Envers integrates with the Hibernate Envers library and offers a convenient and declarative way to enable auditing in a Spring application.


Additional Notes

  • By default, Envers creates dedicated audit tables with _AUD suffix.

  • If you need custom revision listeners, see the RevisionListener interface.


Format code

./mvnw spotless:apply

Run tests

./mvnw clean verify

Run locally

docker-compose -f docker/docker-compose.yml up -d
./mvnw spring-boot:run -Dspring-boot.run.profiles=local

Using Testcontainers at Development Time

You can run TestApplication.java from your IDE directly. You can also run the application using Maven as follows:

./mvnw spring-boot:test-run

Useful Links

  • Swagger UI: http://localhost:8080/swagger-ui.html

  • Actuator Endpoint: http://localhost:8080/actuator

  • Grafana : http://localhost:3000 (admin/admin)

  • Prometheus : http://localhost:9090/graph

  • Alerts: http://localhost:9090/alerts

  • Alerts Stats: http://localhost:9093/

Update to Spring Boot 3

  • Removed problem-spring-web-starter and replaced with Spring OOTB spring.mvc.problemdetails.enabled=true

  • Migrated from javax namespace to jakarta namespace

  • By Default hibernate_sequence is not used instead tablename_seq is used while mapping sequence name and pooled-lo generation strategy is used OOTB

Reference:

  • Alerts - https://github.com/emredmrcan/tutorials/tree/main/monitoring

  • Auditing Strategy - https://vladmihalcea.com/the-best-way-to-implement-an-audit-log-using-hibernate-envers/

Hibernate Envers