javaspring-bootmavenjpahibernate-envers

Spring boot 3 + Envers


I am migrating an application to Spring Boot 3 that uses Hibernate Envers with @Audited annotations. But I cannot find Spring Data Envers after version 2.7 which go to end of support. https://spring.io/projects/spring-data-envers#support

It looks like Envers has been integrated with Spring Data JPA but I can't find any matching annotations in this. Is it still possible to use @Audited annotations in Spring Boot 3?

As of version 3.0, this project has been merged into Spring Data JPA. https://spring.io/projects/spring-data-envers pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Solution

  • As I know, you have to add hibernate-envers dependency to be able to audit the table:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-envers</artifactId>
        <version>6.4.2.Final</version> //latest version, change if it’s needed
    </dependency>
    

    After that you will be able to use what you want.