Using Maven, Liquibase and Hibernate in Spring Boot to generate Diff-Files between a Database and Entities yields Error

Viewed 62

I am trying to generate a Diff-File using Liquibase and Hibernate in a Spring Boot Application that contains the changes between the database I am using and my JPA entities. I am following this tutorial: https://www.baeldung.com/liquibase-refactor-schema-of-java-app (particularly step 7).

However, when executing the mvn liquidate:diff command, I am only getting the following error:

liquibase.exception.DatabaseException: java.lang.RuntimeException: Driver class was not specified and could not be determined from the url (hibernate:spring:com.example.demo?dialect=org.hibernate.dialect.PostgreSQLDialect& hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy& hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)

I have already searched the Internet and there are people that had similar issues, however their solutions did not work in my case.

Here is my liquidate.properties file:

url = jdbc:postgresql://localhost:5432/employeediff
username = myuser
password =
driver=org.postgresql.Driver
classpath=/usr/local/opt/liquibase/internal/lib/postgresql.jar

changeLogFile = src/main/resources/db/changelog/changelog-master.xml
diffChangeLogFile = src/main/resources/db/changelog/diffchangelog.xml

referenceUrl= hibernate:spring:com.example.demo?dialect=org.hibernate.dialect.PostgreSQLDialect

This is my pom.xml file:

<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-web</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.liquibase/liquibase-maven-plugin -->
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>4.10.0</version>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>4.1.0</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
<!--            <scope>runtime</scope>-->
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>4.1.0</version>
                <configuration>
                    <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate5</artifactId>
                        <version>3.6</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-beans</artifactId>
                        <version>5.3.22</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.data</groupId>
                        <artifactId>spring-data-jpa</artifactId>
                        <version>2.7.2</version>
                    </dependency>
                    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-jdbc</artifactId>
                        <version>2.7.3</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

Any help is highly appreciated! Thank you very much!

Kind regards

1 Answers

I found this solution on another site, but it has horrible pop-ups so I'll spare you the link unless you really want it:

The problem was with my referenceUrl in liquibase.properties The referenceUrl is liquibase-hibernate using package scan, so the url has to liquibase-hibernate start with hibernate:spring:

I changed

referenceUrl=com.sample.App?=org.hibernate.dialect.PostgreSQLDialect

into

referenceUrl=hibernate:spring:com.sample.App?dialect=org.hibernate.dialect.PostgreSQLDialect

This solved my problem.

Related