Gradle + ejb + hibernate cannot diffChangeLog

I am trying to make gradle + hibernate work. I did it with gradle + spring + hibernate, but this project is using ejb hibernate.

build.gradle
    plugins {
    //    id 'org.springframework.boot' version '2.3.4.RELEASE'
        id 'io.spring.dependency-management' version '1.0.10.RELEASE'
        id 'java'
        id 'org.liquibase.gradle' version '2.0.4'
    }
    ...

    repositories {
        mavenCentral()
    }
    dependencies {
        compile project(':xxx'),
       ...

        liquibaseRuntime 'org.liquibase:liquibase-core:4.1.1'
        liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:3.0.0'
        liquibaseRuntime 'mysql:mysql-connector-java:8.0.22'
        liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:4.1.1'
        liquibaseRuntime sourceSets.main.runtimeClasspath
        liquibaseRuntime sourceSets.main.output
        liquibaseRuntime("ch.qos.logback:logback-core:1.2.3")
        liquibaseRuntime("ch.qos.logback:logback-classic:1.2.3")
        implementation('org.liquibase:liquibase-core:4.1.1')
    }

    def props = new Properties()
    file("src/main/resources/liquibase.properties").withInputStream { props.load(it) }

    diff.dependsOn assemble
    diffChangeLog.dependsOn assemble

    liquibase {
        activities {
            dev {
                driver 'com.mysql.cj.jdbc.Driver'
                changeLogFile props.getProperty("liquibase.changelog.main")
                url 'jdbc:mysql://localhost:3306/demo2'
                username 'xxx'
                password 'xxx'
                referenceDriver "liquibase.ext.hibernate.database.connection.HibernateDriver"
                referenceUrl props.getProperty("liquibase.changelog.referenceUrl")
            }
        }
        runList = 'dev'
    }
    ...

liquibase.properties
liquibase.changelog.main=src/main/resources/db/changelog/db.changelog-master.groovy
liquibase.changelog.classpath=classpath:db/changelog/db.changelog-master.groovy
liquibase.changelog.referenceUrl=hibernate:ejb3:test?dialect=org.hibernate.dialect.MySQL5Dialect

I am able to execute update / generate / changelogSync, but not diffChangeLog. There I am getting the following:
15:18:42.772 [QUIET] [system.out] Starting Liquibase at 15:18:42 (version 4.1.1 #10 built at 2020-10-12 19:24+0000)
15:18:42.841 [ERROR] [system.err] [2020-10-22 15:18:42] INFO [liquibase.servicelocator] Cannot load service: liquibase.database.Database: Provider liquibase.ext.hibernate.database.HibernateSpringBeanDatabase could not be instantiated
15:18:42.842 [ERROR] [system.err] [2020-10-22 15:18:42] INFO [liquibase.servicelocator] Cannot load service: liquibase.database.Database: Provider liquibase.ext.hibernate.database.HibernateSpringPackageDatabase could not be instantiated
15:18:43.341 [ERROR] [system.err] [2020-10-22 15:18:43] INFO [liquibase.ext] Reading hibernate configuration hibernate:ejb3:test?dialect=org.hibernate.dialect.MySQL5Dialect
15:18:43.356 [ERROR] [system.err] log4j:WARN No appenders could be found for logger (org.jboss.logging).
15:18:43.356 [ERROR] [system.err] log4j:WARN Please initialize the log4j system properly.
15:18:43.356 [ERROR] [system.err] log4j:WARN See Apache log4j 1.2 - Frequently Asked Technical Questions for more info.
15:18:43.382 [QUIET] [system.out] Unexpected error running Liquibase: Unknown reason
15:18:43.382 [QUIET] [system.out] For more information, please use the --logLevel flag
15:18:43.384 [ERROR] [system.err] [2020-10-22 15:18:43] SEVERE [liquibase.integration] Unexpected error running Liquibase: Unknown reason
15:18:43.384 [ERROR] [system.err] liquibase.exception.DatabaseException: java.lang.NullPointerException
15:18:43.384 [ERROR] [system.err] at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:131)
15:18:43.384 [ERROR] [system.err] at liquibase.integration.commandline.Main.createReferenceDatabaseFromCommandParams(Main.java:2041)
15:18:43.384 [ERROR] [system.err] at liquibase.integration.commandline.Main.doMigration(Main.java:1487)
15:18:43.384 [ERROR] [system.err] at liquibase.integration.commandline.Main$1.lambda$run$0(Main.java:361)
15:18:43.384 [ERROR] [system.err] at liquibase.Scope.lambda$child$0(Scope.java:160)
15:18:43.384 [ERROR] [system.err] at liquibase.Scope.child(Scope.java:169)
15:18:43.384 [ERROR] [system.err] at liquibase.Scope.child(Scope.java:159)
15:18:43.384 [ERROR] [system.err] at liquibase.Scope.child(Scope.java:138)
15:18:43.384 [ERROR] [system.err] at liquibase.Scope.child(Scope.java:222)
15:18:43.384 [ERROR] [system.err] at liquibase.Scope.child(Scope.java:226)
15:18:43.384 [ERROR] [system.err] at liquibase.integration.commandline.Main$1.run(Main.java:360)
15:18:43.384 [ERROR] [system.err] at liquibase.integration.commandline.Main$1.run(Main.java:193)
15:18:43.384 [ERROR] [system.err] at liquibase.Scope.child(Scope.java:169)
15:18:43.384 [ERROR] [system.err] at liquibase.Scope.child(Scope.java:145)
15:18:43.384 [ERROR] [system.err] at liquibase.integration.commandline.Main.run(Main.java:193)
15:18:43.384 [ERROR] [system.err] at liquibase.integration.commandline.Main.main(Main.java:156)
15:18:43.384 [ERROR] [system.err] Caused by: java.lang.NullPointerException
15:18:43.384 [ERROR] [system.err] at liquibase.ext.hibernate.database.HibernateEjb3Database.buildMetadataFromPath(HibernateEjb3Database.java:59)
15:18:43.385 [ERROR] [system.err] at liquibase.ext.hibernate.database.HibernateDatabase.buildMetadata(HibernateDatabase.java:143)
15:18:43.385 [ERROR] [system.err] at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:83)
15:18:43.385 [ERROR] [system.err] at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:120)
15:18:43.385 [ERROR] [system.err] at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:140)
15:18:43.385 [ERROR] [system.err] at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:96)
15:18:43.385 [ERROR] [system.err] … 15 more
15:18:43.385 [ERROR] [system.err]

Hi @trixobird!

I am not sure what’s going on here, and I am not an ejb expert but could we see the complete stack trace? Looking for a ‘caused by…’ block possibly.

Also, on these integrations I think maybe will have to reach out to our liquibase legend @nvoxland.

Ronak

Hi @ronak, thank you for your answer. Unfortunately I am also new to ejb, just changing companies. Here is the full stack. Please let me know if there is anything else that I can do to help.

08:47:29.421 [ERROR] [system.err] [2020-10-28 08:47:29] SEVERE [liquibase.integration] Unexpected error running Liquibase: Unknown reason
08:47:29.421 [ERROR] [system.err] liquibase.exception.DatabaseException: java.lang.NullPointerException
08:47:29.422 [ERROR] [system.err] 	at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:131)
08:47:29.422 [ERROR] [system.err] 	at liquibase.integration.commandline.Main.createReferenceDatabaseFromCommandParams(Main.java:2041)
08:47:29.422 [ERROR] [system.err] 	at liquibase.integration.commandline.Main.doMigration(Main.java:1487)
08:47:29.422 [ERROR] [system.err] 	at liquibase.integration.commandline.Main$1.lambda$run$0(Main.java:361)
08:47:29.422 [ERROR] [system.err] 	at liquibase.Scope.lambda$child$0(Scope.java:160)
08:47:29.422 [ERROR] [system.err] 	at liquibase.Scope.child(Scope.java:169)
08:47:29.422 [ERROR] [system.err] 	at liquibase.Scope.child(Scope.java:159)
08:47:29.422 [ERROR] [system.err] 	at liquibase.Scope.child(Scope.java:138)
08:47:29.422 [ERROR] [system.err] 	at liquibase.Scope.child(Scope.java:222)
08:47:29.422 [ERROR] [system.err] 	at liquibase.Scope.child(Scope.java:226)
08:47:29.422 [ERROR] [system.err] 	at liquibase.integration.commandline.Main$1.run(Main.java:360)
08:47:29.422 [ERROR] [system.err] 	at liquibase.integration.commandline.Main$1.run(Main.java:193)
08:47:29.422 [ERROR] [system.err] 	at liquibase.Scope.child(Scope.java:169)
08:47:29.422 [ERROR] [system.err] 	at liquibase.Scope.child(Scope.java:145)
08:47:29.422 [ERROR] [system.err] 	at liquibase.integration.commandline.Main.run(Main.java:193)
08:47:29.422 [ERROR] [system.err] 	at liquibase.integration.commandline.Main.main(Main.java:156)
08:47:29.422 [ERROR] [system.err] Caused by: java.lang.NullPointerException
08:47:29.422 [ERROR] [system.err] 	at liquibase.ext.hibernate.database.HibernateEjb3Database.buildMetadataFromPath(HibernateEjb3Database.java:59)
08:47:29.422 [ERROR] [system.err] 	at liquibase.ext.hibernate.database.HibernateDatabase.buildMetadata(HibernateDatabase.java:143)
08:47:29.422 [ERROR] [system.err] 	at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:83)
08:47:29.422 [ERROR] [system.err] 	at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:120)
08:47:29.422 [ERROR] [system.err] 	at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:140)
08:47:29.422 [ERROR] [system.err] 	at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:96)
08:47:29.422 [ERROR] [system.err] 	... 15 more
08:47:29.422 [ERROR] [system.err]

Hi @trixobird,

I hope this helps, I followed the stack trace and can see that liqubase is choking in the DatabaseFactory call out to the hibernate extension:


public Database openDatabase(String url,
String username,
String password,
String driver,
String databaseClass,
String driverPropertiesFile,
String propertyProviderClass,
ResourceAccessor resourceAccessor) throws DatabaseException {
return this.findCorrectDatabaseImplementation(openConnection(url, username, password, driver, databaseClass, driverPropertiesFile, propertyProviderClass, resourceAccessor));
}

Would you share the driver and url you are using for your database?

Hi @ronak , apologies for the slightly delayed answer. I think I have shared the db connection detail in the initial post, I hope this is what you are asking for. I am reposting it here:

#gradle.build
    liquibase {
        activities {
            dev {
                driver 'com.mysql.cj.jdbc.Driver'
                changeLogFile props.getProperty("liquibase.changelog.main")
                url 'jdbc:mysql://localhost:3306/demo2'
                username 'root'
                password 'root'
                referenceDriver "liquibase.ext.hibernate.database.connection.HibernateDriver"
                referenceUrl props.getProperty("liquibase.changelog.referenceUrl")
            }
        }
        runList = 'dev'
    }

#liquibase.properties
liquibase.changelog.main=src/main/resources/db/changelog/db.changelog-master.groovy
liquibase.changelog.classpath=classpath:db/changelog/db.changelog-master.groovy
liquibase.changelog.referenceUrl=hibernate:ejb3:test?dialect=org.hibernate.dialect.MySQL5Dialect

Thank you very much for your time!

Hi @trixobird,

Am I right in thinking you are trying to compare a mysql database with a hibernate connection?

I think this has to be something like (judging by this issue):
hibernate:spring:com…? dialect=org.hibernate.dialect.mysql --driver=org.mysql.Driver