diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java index ac6d814599f0..0b0e7c620fbc 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java @@ -128,12 +128,7 @@ public JdbcEnvironment initiateService(Map configurationValues, explicitDatabaseMinorVersion, explicitDatabaseVersion); } - else if ( explicitDialectConfiguration( - configurationValues, - explicitDatabaseName, - explicitDatabaseMajorVersion, - explicitDatabaseMinorVersion, - explicitDatabaseVersion) ) { + else if ( explicitDialectConfiguration( explicitDatabaseName, configurationValues ) ) { return getJdbcEnvironmentWithExplicitConfiguration( configurationValues, registry, @@ -394,14 +389,9 @@ private static void logDatabaseAndDriver(DatabaseMetaData dbmd) throws SQLExcept } } - private static boolean explicitDialectConfiguration( - Map configurationValues, - String explicitDatabaseName, - Integer explicitDatabaseMajorVersion, - Integer explicitDatabaseMinorVersion, - String explicitDatabaseVersion) { - return ( isNotEmpty(explicitDatabaseVersion) || explicitDatabaseMajorVersion != null || explicitDatabaseMinorVersion != null ) - && ( isNotEmpty(explicitDatabaseName) || isNotNullAndNotEmpty( configurationValues.get(DIALECT) ) ); + private static boolean explicitDialectConfiguration(String explicitDatabaseName, + Map configurationValues) { + return isNotEmpty( explicitDatabaseName ) || isNotNullAndNotEmpty( configurationValues.get( DIALECT ) ); } private static boolean isNotNullAndNotEmpty(Object o) { @@ -502,7 +492,7 @@ public DialectResolutionInfoImpl( String databaseName, String databaseVersion, int databaseMajorVersion, - int databaseMinorVersion, + int databaseMinorVersion, int databaseMicroVersion, String driverName, int driverMajorVersion, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/metadata/MetadataAccessTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/metadata/MetadataAccessTests.java index 11db3d4c0404..601cd48b410f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/metadata/MetadataAccessTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/metadata/MetadataAccessTests.java @@ -45,7 +45,8 @@ void testAccessAllowed() { registryBuilder.applySetting( AvailableSettings.JAKARTA_JDBC_PASSWORD, TestingDatabaseInfo.PASS ); // make certain there is no explicit dialect configured - assertThat( registryBuilder.getSettings() ).doesNotContainKey( JdbcSettings.DIALECT ); + assertThat( registryBuilder.getSettings() ) + .doesNotContainKeys( JdbcSettings.DIALECT, JdbcSettings.JAKARTA_HBM2DDL_DB_NAME ); try (StandardServiceRegistry registry = registryBuilder.build()) { final JdbcEnvironment jdbcEnvironment = registry.getService( JdbcEnvironment.class ); @@ -62,6 +63,8 @@ void testAccessDisabledExplicitDialect() { registryBuilder.applySetting( JdbcSettings.ALLOW_METADATA_ON_BOOT, false ); registryBuilder.applySetting( JdbcSettings.DIALECT, "org.hibernate.dialect.OracleDialect" ); + assertThat( registryBuilder.getSettings() ) + .doesNotContainKeys( JdbcSettings.JAKARTA_HBM2DDL_DB_NAME ); try (StandardServiceRegistry registry = registryBuilder.build()) { final JdbcEnvironment jdbcEnvironment = registry.getService( JdbcEnvironment.class ); @@ -71,10 +74,29 @@ void testAccessDisabledExplicitDialect() { } @Test - void testAccessDisabledNoDialect() { + @Jira("https://hibernate.atlassian.net/browse/HHH-18079") + void testAccessDisabledExplicitProductName() { final StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(); registryBuilder.clearSettings(); - assertThat( registryBuilder.getSettings() ).doesNotContainKey( JdbcSettings.DIALECT ); + + registryBuilder.applySetting( JdbcSettings.ALLOW_METADATA_ON_BOOT, false ); + registryBuilder.applySetting( JdbcSettings.JAKARTA_HBM2DDL_DB_NAME, "Oracle" ); + assertThat( registryBuilder.getSettings() ) + .doesNotContainKeys( JdbcSettings.DIALECT ); + + try (StandardServiceRegistry registry = registryBuilder.build()) { + final JdbcEnvironment jdbcEnvironment = registry.getService( JdbcEnvironment.class ); + final Dialect dialect = jdbcEnvironment.getDialect(); + assertThat( dialect ).isInstanceOf( OracleDialect.class ); + } + } + + @Test + void testAccessDisabledNoDialectNorProductName() { + final StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(); + registryBuilder.clearSettings(); + assertThat( registryBuilder.getSettings() ) + .doesNotContainKeys( JdbcSettings.DIALECT, JdbcSettings.JAKARTA_HBM2DDL_DB_NAME ); registryBuilder.applySetting( JdbcSettings.ALLOW_METADATA_ON_BOOT, false ); try (StandardServiceRegistry registry = registryBuilder.build()) {