liquibase / liquibase-hibernate

Liquibase Hibernate Integration
Apache License 2.0
271 stars 158 forks source link

Unable to run diffChangeLog with spring boot with java 11 #192

Closed jozefmorvay closed 7 months ago

jozefmorvay commented 5 years ago

Hello. I am unable to get this running for my project on java 11 with spring boot. My build.gradle:

buildscript {
    ext {
        springBootVersion = '2.1.0.RELEASE'
        runList = 'main'
        diffLog = '$projectDir/src/main/resources/db/changelog/db.changelog-master.xml'
    }
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'org.liquibase:liquibase-gradle-plugin:2.0.1'
//        classpath 'org.liquibase:liquibase-core'
        classpath 'org.liquibase:liquibase:3.7.0-SNAPSHOT'
        classpath 'org.postgresql:postgresql:42.2.5'
        classpath 'org.liquibase.ext:liquibase-hibernate5:3.6'
        classpath 'org.springframework.data:spring-data-jpa:2.1.2.RELEASE'
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.liquibase.gradle'

group = 'com.company'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 11.0
diffLog = '$projectDir/src/main/resources/db/changelog/db.changelog-{$version}.xml'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
    implementation('org.springframework.boot:spring-boot-starter-security')
    implementation('org.springframework.boot:spring-boot-starter-webflux')
    implementation('org.springframework.session:spring-session-core')
    implementation('org.liquibase.ext:liquibase-hibernate5:3.6')
//  implementation('org.liquibase:liquibase-core:3.6.2')
    implementation('org.liquibase:liquibase:3.7.0-SNAPSHOT')
    implementation('io.reactivex.rxjava2:rxjava:2.2.3')
    implementation("org.hsqldb:hsqldb:2.4.1")
    implementation("org.postgresql:postgresql:42.2.5")
    compileOnly('org.projectlombok:lombok:1.18.4')

    testImplementation('org.springframework.boot:spring-boot-starter-test')
    testImplementation('io.projectreactor:reactor-test')
    testImplementation('org.springframework.security:spring-security-test')

    liquibaseRuntime('org.springframework.boot:spring-boot-starter-data-jpa:2.1.0.RELEASE')
    liquibaseRuntime('org.liquibase.ext:liquibase-hibernate5:3.6')
//    liquibaseRuntime('org.liquibase:liquibase-core:3.6.2')
    liquibaseRuntime('org.liquibase:liquibase:3.7.0-SNAPSHOT')
    liquibaseRuntime("org.postgresql:postgresql:42.2.5")
    liquibaseRuntime("javax.xml.bind:jaxb-api:2.3.1")
    liquibaseRuntime sourceSets.main.output
}

diff.dependsOn compileJava
diffChangeLog.dependsOn compileJava

liquibase {
    activities {
        main {
            changeLogFile project.ext.diffLog
            driver 'org.postgresql.Driver'
            url 'jdbc:postgresql://localhost:5432/database'
            username 'username'
            password 'password'
            referenceUrl 'hibernate:spring:com.company.warehouse.db?' +
                    'dialect=org.hibernate.dialect.PostgreSQL94Dialect&' +
                    'hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&' +
                    'hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
//            referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
        }
        runList = project.ext.runList
    }
}

When running either diff or diffChangeLog, I am getting this:

Unexpected error running Liquibase: java.lang.NullPointerException
liquibase.exception.LiquibaseException: liquibase.command.CommandExecutionException: java.lang.NullPointerException
    at liquibase.integration.commandline.CommandLineUtils.doDiff(CommandLineUtils.java:200)
    at liquibase.integration.commandline.Main.doMigration(Main.java:1004)
    at liquibase.integration.commandline.Main.lambda$run$0(Main.java:187)
    at liquibase.Scope.child(Scope.java:125)
    at liquibase.Scope.child(Scope.java:106)
    at liquibase.Scope.child(Scope.java:138)
    at liquibase.Scope.child(Scope.java:142)
    at liquibase.integration.commandline.Main.run(Main.java:186)
    at liquibase.integration.commandline.Main.main(Main.java:125)
Caused by: liquibase.command.CommandExecutionException: java.lang.NullPointerException
    at liquibase.command.AbstractCommand.execute(AbstractCommand.java:24)
    at liquibase.integration.commandline.CommandLineUtils.doDiff(CommandLineUtils.java:198)
    ... 8 common frames omitted
Caused by: java.lang.NullPointerException: null
    at liquibase.snapshot.jvm.JdbcSnapshotGenerator.getDatabaseCatalogNames(JdbcSnapshotGenerator.java:147)
    at liquibase.snapshot.jvm.CatalogSnapshotGenerator.snapshotObject(CatalogSnapshotGenerator.java:34)
    at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:66)
    at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:49)
    at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:286)
    at liquibase.snapshot.DatabaseSnapshot.init(DatabaseSnapshot.java:96)
    at liquibase.snapshot.DatabaseSnapshot.<init>(DatabaseSnapshot.java:59)
    at liquibase.snapshot.JdbcDatabaseSnapshot.<init>(JdbcDatabaseSnapshot.java:38)
    at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:215)
    at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:188)
    at liquibase.command.core.DiffCommand.createReferenceSnapshot(DiffCommand.java:221)
    at liquibase.command.core.DiffCommand.createDiffResult(DiffCommand.java:143)
    at liquibase.command.core.DiffCommand.run(DiffCommand.java:135)
    at liquibase.command.AbstractCommand.execute(AbstractCommand.java:19)
    ... 9 common frames omitted

This is caused by HibernateConnectionMetadata class, which I do not understand the purpose of. It just returns null/0/false for everything. So then I tried commenting out referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver' and replaced the line with: driver 'org.postgresql.Driver' But that amounted to getting a new exception instead:

Unexpected error running Liquibase: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:sk.imuna.warehouse.db?dialect=org.hibernate.dialect.PostgreSQL94Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:sk.imuna.warehouse.db?dialect=org.hibernate.dialect.PostgreSQL94Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:131)
    at liquibase.integration.commandline.Main.createReferenceDatabaseFromCommandParams(Main.java:1407)
    at liquibase.integration.commandline.Main.doMigration(Main.java:1005)
    at liquibase.integration.commandline.Main.lambda$run$0(Main.java:187)
    at liquibase.Scope.child(Scope.java:125)
    at liquibase.Scope.child(Scope.java:106)
    at liquibase.Scope.child(Scope.java:138)
    at liquibase.Scope.child(Scope.java:142)
    at liquibase.integration.commandline.Main.run(Main.java:186)
    at liquibase.integration.commandline.Main.main(Main.java:125)
Caused by: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:sk.imuna.warehouse.db?dialect=org.hibernate.dialect.PostgreSQL94Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)
    at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:247)
    at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:142)
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:96)
    ... 9 common frames omitted
Caused by: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:sk.imuna.warehouse.db?dialect=org.hibernate.dialect.PostgreSQL94Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy)
    at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:193)
    ... 11 common frames omitted

No idea what that means since postgre driver is clearly listed as a liquibaseRuntime dependency. This may not be an issue of this project, I am rather looking for an advice how to proceed.

┆Issue is synchronized with this Jira Bug by Unito

muasif commented 5 years ago

I am getting the same error. It is like the catalogs object is coming as null when I am using it with the MySQL database

image

Any help?

medberg commented 5 years ago

I am getting the same error. It is like the catalogs object is coming as null when I am using it with the MySQL database

image

Any help?

@muasif Did you ever figure this out? Running into the exact same issue.

Julieng50 commented 5 years ago

Hello, Adding this line to my gradle dependencies worked for me :
liquibaseRuntime 'org.springframework.boot:spring-boot-starter-data-jpa'

But it seems like you already got it.
Should be a problem with another dependency.

mklueh commented 3 years ago

I´m running into the same issue, but I don´t use Spring JPA but Quarkus with Panache instead

skambo commented 3 years ago

Hello, Did anyone ever find a solution to this? Running into the same issue..

Syndlex commented 3 years ago

I had this Problem: I defined the ref URL in the liquibase.properties file. And put a Multiline string there.

referenceUrl:"hibernate:spring:de.cop.business.model\
  ?dialect=org.hibernate.dialect.SQLServerDialect"

I forgot that Properties is not yaml and " is invalid.

Removing the " worked. Parsing the URI should really be validated before executing on it.

siddharthapd commented 11 months ago

I´m running into the same issue, but I don´t use Spring JPA but Quarkus with Panache instead

Hello, I was able to resolve this today. just include spring-data-jpa and spring-data-envers in liquibaseRuntime. That should solve the issue. I am afraid I ran into multiple issue when configuring with quarkus . I believe we should have equivalent support with Quarkus just like spring bean with reference url like hibernate:quarks:<entitiespackage>?dialect=<hibernateGenericDialect> something like this

filipelautert commented 7 months ago

Hi - we have some fixes and workarounds on this answer. Please reopen the issue if it is not fixable by using any of them.