Search code examples
springspring-bootliquibaseliquibase-hibernateliquibase-maven-plugin

liquibase-hibernate6: java.lang.UnsupportedOperationException: The application must supply JDBC connections


I've tried adding Liquibase to my project and to get the diff between entities and the database I've also added liquibase-hibernate6 to POM file.

When I try the command:

mvn liquibase:diff

I get there error:

[WARNING] HHH000181: No appropriate connection provider encountered, assuming application ...
[WARNING] HHH000342: Could not obtain connection to query metadata
java.lang.UnsupportedOperationException: The application must supply JDBC connections

This is a part of the POM file:

    <plugin>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-maven-plugin</artifactId>
        <version>${liquibase.version}</version>
        <configuration>
            <propertyFile>src/main/resources/liquibase/config/liquibase.properties</propertyFile>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>org.liquibase.ext</groupId>
                <artifactId>liquibase-hibernate6</artifactId>
                <version>4.23.1</version>
            </dependency>
        </dependencies>
    </plugin>

And the liquibase.properties

changeLogFile=src/main/resources/liquibase/liquibase-changeLog.xml
diffChangeLogFile=src/main/resources/liquibase/liquibase-changeLog.xml
outputChangeLogFile=src/main/resources/liquibase/liquibase-new-changeLog.xml
url=jdbc:postgresql://localhost:5432/forum
defaultSchemaName=public
username=postgres
password=123456
driver=org.postgresql.Driver

referenceDefaultSchemaName=public
referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
referenceUrl=hibernate:spring:ir.renglab.forum.domain?dialect=org.hibernate.dialect.PostgreSQLDialect

The main point is that finally it built successfully and the changelog file is created but how can I fix the error? and what is the problem?

PS: I'm using Spring-Boot version 3.1.3


Solution

  • I once solved the same issue under spring 2.6 and hibernate 5 by placing a hibernate.properties file with the same connection infos as the liquibase.properties file onto the classpath (generally the root of the resources folder) as well

    e.g. hibernate.properties:

    hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver
    hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
    hibernate.connection.url=jdbc:mysql://localhost:3306/databasename?useSSL=false
    hibernate.connection.username=root
    hibernate.connection.password=
    

    Unfortunately now under spring 3 and hibernate 6 it seems to not to work anymore. But I am using Gradle instead of Maven now. So perhaps it still works for you.

    [UPDATE] It seems to be a known issue: Github Issue

    [UPDATE2] I was able to make it work under gradle with the hibernate.properties file by adding the location of the file to the liquibaseRuntime: liquibaseRuntime(javaExtension.sourceSets.getByName("main").resources.sourceDirectories)