Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The application must supply JDBC connections When Running Diff After Upgrade #742

Open
imperiouslol opened this issue Jan 7, 2025 · 1 comment

Comments

@imperiouslol
Copy link

Hello,

I've recently upgraded to Spring Boot 2.7 / Liquibase 4.26 / Hibernate 5.6.15.Final and I'm no longer able to run a diffChangeLog with the following configuration using the liquibase-gradle-plugin (2.2.0):

...
liquibaseRuntime 'org.springframework.boot:spring-boot-starter-data-jpa:2.7.18'
liquibaseRuntime 'org.liquibase:liquibase-core:4.26.0'
liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:4.26.0'
liquibaseRuntime sourceSets.main.output
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:3.0.1'
liquibaseRuntime 'info.picocli:picocli:4.6.3'
...
...
changeLogFile "${project.rootDir}/jau-bom-sample/src/main/resources/db/changelog/oracle/changes/sqlscripts/"+"${fileName}"
url "jdbc:h2:tcp://localhost:${databasePort}/jbsdb;INIT=CREATE SCHEMA IF NOT EXISTS JBS"
username project.ext.username
password project.ext.password
referenceUrl 'hibernate:spring:gov.osc.common.jau.bom.sample.model?dialect=org.hibernate.dialect.Oracle10gDialect'
referenceDefaultSchemaName 'HIBERNATE'
defaultSchemaName 'JBS'
includeSchema true
...

Running my diff results in the following stacktrace:

Starting Liquibase at 11:13:42 (version 4.26.0 #1141 built at 2024-02-06 21:31+0000)
Liquibase Version: 4.26.0
[2025-01-07 11:13:42] INFO [liquibase.ui] Liquibase Version: 4.26.0
Liquibase Open Source 4.26.0 by Liquibase
[2025-01-07 11:13:42] INFO [liquibase.ui] Liquibase Open Source 4.26.0 by Liquibase
[2025-01-07 11:13:42] INFO [liquibase.integration] Starting command execution.
[2025-01-07 11:13:42] INFO [liquibase.ext] Reading hibernate configuration hibernate:spring:gov.osc.common.jau.bom.sample.model?dialect=org.hibernate.dialect.Oracle10gDialect
...
...
...
11:13:43.078 [main] WARN org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator - HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
11:13:43.079 [main] WARN org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator - HHH000342: Could not obtain connection to query metadata
java.lang.UnsupportedOperationException: The application must supply JDBC connections
        at org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:44)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:272)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:246)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:223)
        at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:175)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:295)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:252)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:223)
        at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:173)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1460)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1494)
        at liquibase.ext.hibernate.database.HibernateEjb3Database.buildMetadataFromPath(HibernateEjb3Database.java:59)
        at liquibase.ext.hibernate.database.HibernateDatabase.buildMetadata(HibernateDatabase.java:143)
        at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:83)
        at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:133)
        at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:153)
        at liquibase.command.core.helpers.AbstractDatabaseConnectionCommandStep.createDatabaseObject(AbstractDatabaseConnectionCommandStep.java:73)
        at liquibase.command.core.helpers.ReferenceDbUrlConnectionCommandStep.obtainDatabase(ReferenceDbUrlConnectionCommandStep.java:89)
        at liquibase.command.core.helpers.ReferenceDbUrlConnectionCommandStep.run(ReferenceDbUrlConnectionCommandStep.java:70)
        at liquibase.command.CommandScope.execute(CommandScope.java:217)
        at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:55)
        at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:24)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at liquibase.integration.commandline.LiquibaseCommandLine.lambda$execute$2(LiquibaseCommandLine.java:390)
        at liquibase.Scope.child(Scope.java:195)
        at liquibase.Scope.child(Scope.java:171)
        at liquibase.integration.commandline.LiquibaseCommandLine.lambda$execute$3(LiquibaseCommandLine.java:365)
        at liquibase.Scope.child(Scope.java:195)
        at liquibase.Scope.child(Scope.java:171)
        at liquibase.integration.commandline.LiquibaseCommandLine.execute(LiquibaseCommandLine.java:362)
        at liquibase.integration.commandline.LiquibaseCommandLine.main(LiquibaseCommandLine.java:102)
...
...
...
[2025-01-07 11:22:23] INFO [liquibase.command] Logging exception.
ERROR: Exception Details
[2025-01-07 11:22:23] INFO [liquibase.ui] ERROR: Exception Details
ERROR: Exception Primary Class:  UnsupportedOperationException
[2025-01-07 11:22:23] INFO [liquibase.ui] ERROR: Exception Primary Class:  UnsupportedOperationException
ERROR: Exception Primary Reason: The application must supply JDBC connections
[2025-01-07 11:22:23] INFO [liquibase.ui] ERROR: Exception Primary Reason: The application must supply JDBC connections
ERROR: Exception Primary Source: 4.26.0
[2025-01-07 11:22:23] INFO [liquibase.ui] ERROR: Exception Primary Source: 4.26.0
[2025-01-07 11:22:23] INFO [liquibase.command] Command execution complete
[2025-01-07 11:22:23] SEVERE [liquibase.integration] [PersistenceUnit: default] Unable to build Hibernate SessionFactory
  - Caused by: The application must supply JDBC connections
liquibase.exception.CommandExecutionException: liquibase.exception.DatabaseException: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
        at liquibase.command.CommandScope.execute(CommandScope.java:253)
        at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:55)
        at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:24)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at liquibase.integration.commandline.LiquibaseCommandLine.lambda$execute$2(LiquibaseCommandLine.java:390)
        at liquibase.Scope.child(Scope.java:195)
        at liquibase.Scope.child(Scope.java:171)
        at liquibase.integration.commandline.LiquibaseCommandLine.lambda$execute$3(LiquibaseCommandLine.java:365)
        at liquibase.Scope.child(Scope.java:195)
        at liquibase.Scope.child(Scope.java:171)
        at liquibase.integration.commandline.LiquibaseCommandLine.execute(LiquibaseCommandLine.java:362)
        at liquibase.integration.commandline.LiquibaseCommandLine.main(LiquibaseCommandLine.java:102)
Caused by: liquibase.exception.DatabaseException: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
        at liquibase.command.core.helpers.AbstractDatabaseConnectionCommandStep.createDatabaseObject(AbstractDatabaseConnectionCommandStep.java:105)
        at liquibase.command.core.helpers.ReferenceDbUrlConnectionCommandStep.obtainDatabase(ReferenceDbUrlConnectionCommandStep.java:89)
        at liquibase.command.core.helpers.ReferenceDbUrlConnectionCommandStep.run(ReferenceDbUrlConnectionCommandStep.java:70)
        at liquibase.command.CommandScope.execute(CommandScope.java:217)
        ... 18 more
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1597)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1503)
        at liquibase.ext.hibernate.database.HibernateEjb3Database.buildMetadataFromPath(HibernateEjb3Database.java:59)
        at liquibase.ext.hibernate.database.HibernateDatabase.buildMetadata(HibernateDatabase.java:143)
        at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:83)
        at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:133)
        at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:153)
        at liquibase.command.core.helpers.AbstractDatabaseConnectionCommandStep.createDatabaseObject(AbstractDatabaseConnectionCommandStep.java:73)
        ... 21 more
Caused by: java.lang.UnsupportedOperationException: The application must supply JDBC connections
        at org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:44)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181)
        at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:44)
        at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.jdbcStatement(GenerationTargetToDatabase.java:77)
        at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:53)
        at org.hibernate.hql.spi.id.IdTableHelper.executeIdTableCreationStatements(IdTableHelper.java:184)
        at org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy.finishPreparation(GlobalTemporaryTableBulkIdStrategy.java:126)
        at org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy.finishPreparation(GlobalTemporaryTableBulkIdStrategy.java:44)
        at org.hibernate.hql.spi.id.AbstractMultiTableBulkIdStrategyImpl.prepare(AbstractMultiTableBulkIdStrategyImpl.java:88)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:327)
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1498)
        ... 27 more


Unexpected error running Liquibase: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
  - Caused by: The application must supply JDBC connections

liquibase.exception.CommandExecutionException: liquibase.exception.DatabaseException: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
        at liquibase.command.CommandScope.execute(CommandScope.java:253)
        at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:55)
        at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:24)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at liquibase.integration.commandline.LiquibaseCommandLine.lambda$execute$2(LiquibaseCommandLine.java:390)
        at liquibase.Scope.child(Scope.java:195)
        at liquibase.Scope.child(Scope.java:171)
        at liquibase.integration.commandline.LiquibaseCommandLine.lambda$execute$3(LiquibaseCommandLine.java:365)
        at liquibase.Scope.child(Scope.java:195)
        at liquibase.Scope.child(Scope.java:171)
        at liquibase.integration.commandline.LiquibaseCommandLine.execute(LiquibaseCommandLine.java:362)
        at liquibase.integration.commandline.LiquibaseCommandLine.main(LiquibaseCommandLine.java:102)
Caused by: liquibase.exception.DatabaseException: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
        at liquibase.command.core.helpers.AbstractDatabaseConnectionCommandStep.createDatabaseObject(AbstractDatabaseConnectionCommandStep.java:105)
        at liquibase.command.core.helpers.ReferenceDbUrlConnectionCommandStep.obtainDatabase(ReferenceDbUrlConnectionCommandStep.java:89)
        at liquibase.command.core.helpers.ReferenceDbUrlConnectionCommandStep.run(ReferenceDbUrlConnectionCommandStep.java:70)
        at liquibase.command.CommandScope.execute(CommandScope.java:217)
        ... 18 more
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1597)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1503)
        at liquibase.ext.hibernate.database.HibernateEjb3Database.buildMetadataFromPath(HibernateEjb3Database.java:59)
        at liquibase.ext.hibernate.database.HibernateDatabase.buildMetadata(HibernateDatabase.java:143)
        at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:83)
        at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:133)
        at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:153)
        at liquibase.command.core.helpers.AbstractDatabaseConnectionCommandStep.createDatabaseObject(AbstractDatabaseConnectionCommandStep.java:73)
        ... 21 more
Caused by: java.lang.UnsupportedOperationException: The application must supply JDBC connections
        at org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:44)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181)
        at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:44)
        at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.jdbcStatement(GenerationTargetToDatabase.java:77)
        at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:53)
        at org.hibernate.hql.spi.id.IdTableHelper.executeIdTableCreationStatements(IdTableHelper.java:184)
        at org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy.finishPreparation(GlobalTemporaryTableBulkIdStrategy.java:126)
        at org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy.finishPreparation(GlobalTemporaryTableBulkIdStrategy.java:44)
        at org.hibernate.hql.spi.id.AbstractMultiTableBulkIdStrategyImpl.prepare(AbstractMultiTableBulkIdStrategyImpl.java:88)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:327)
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1498)
        ... 27 more

> Task :jau-bom-sample:diffChangelog FAILED

I've omitted portions of the stacktrace for brevity (let me know if you need the full stack), but essentially I receive a warning, followed by an error for The application must supply JDBC connections.

Something worth noting is that my diff will run "successfully" with only the warning if I remove my JPA @Inheritance(strategy = InheritanceType.JOINED) mapping from one of my entities, or If I change my dialect to something other than Oracle10gDialect. However, diffChangeLog was working properly with these configurations prior to going through this upgrade.

I have followed #616 and related issues / threads closely to attempt to resolve this. This is what caused me to upgrade to version 4.26.0 - the release which addressed this. When looking at the source code for the hibernate6 release of 4.26.0, I can see that the hibernate hibernate.temp.use_jdbc_metadata_defaults flag is being set for all database types, however, when I look at the source code for the backported hibernate5 release (which is what I'm using), I'm only seeing this flag set for HibernateClassicDatabase.

I'm looking for some guidance for how to address this as I'm unable to move forward with my upgrade until this is resolved. Is there something wrong with my configuration? Should I be specifying the HibernateClassicDatabase implementation since that's the only database type that contains this fix for the hibernate5 release?

Any information would be greatly appreciated and thank you for your time!

@imperiouslol
Copy link
Author

imperiouslol commented Jan 15, 2025

Providing a update here, as I've been troubleshooting workarounds. I have a better understanding as to why this is failing when using @Inheritance(strategy = InheritanceType.JOINED) in conjunction with Oracle10gDialect:

When using this configuration, running a diffChangelog will result in hibernate attempting to create temporary HT_ tables for the entities which will fail because it does not have the JDBC connection.

This problem appeared after upgrading hibernate-core from 5.4.32.Final -> 5.6.15.Final. The prior version would fail silently if it could not obtain a JDBC connection when attempting to create temporary tables in IdTableHelper:

public void executeIdTableCreationStatements(...) {
    ...
    ...
    Connection connection;
    try {
        connection = connectionAccess.obtainConnection();
    }
    catch (UnsupportedOperationException e) {
        // assume this comes from org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl
        log.debug( "Unable to obtain JDBC connection; assuming ID tables already exist or wont be needed" );
        return;
    }
    ...
    ...
}

When upgrading to the newer version, this no longer fails silently, and results in the failure stack originally posted in the issue.

My workaround options are:

  1. Create a hibernate.properties file and define my connections
    • This has unwanted results, as running a diffChangelog now results in temporary HT_ tables getting created in my schema for the table inheritance due to the connections getting picked up successfully
  2. Create a hibernate.properties file and set the following flag:
    hibernate.hql.bulk_id_strategy=org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy
    • This changes the strategy which prevents temporary tables from being created

I'm opting for 2 for the time being, which prevents my diffChangelog from failing.

At this point I'm in a state where I'm still getting the The application must supply JDBC connections WARNING when running my diff. Any guidance would be greatly appreciated and thank you again for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant