HHH-18079 Default to minimum supported DB version in more cases

In particular when using hibernate.boot.allow_jdbc_metadata_access=false with jakarta.persistence.database-product-name
This commit is contained in:
Yoann Rodière 2024-05-06 18:07:45 +02:00 committed by Steve Ebersole
parent b98ee83b8d
commit 73edbac469
2 changed files with 30 additions and 18 deletions

View File

@ -128,12 +128,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
explicitDatabaseMinorVersion,
explicitDatabaseVersion);
}
else if ( explicitDialectConfiguration(
configurationValues,
explicitDatabaseName,
explicitDatabaseMajorVersion,
explicitDatabaseMinorVersion,
explicitDatabaseVersion) ) {
else if ( explicitDialectConfiguration( explicitDatabaseName, configurationValues ) ) {
return getJdbcEnvironmentWithExplicitConfiguration(
configurationValues,
registry,
@ -394,14 +389,9 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
}
}
private static boolean explicitDialectConfiguration(
Map<String, Object> 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<String, Object> configurationValues) {
return isNotEmpty( explicitDatabaseName ) || isNotNullAndNotEmpty( configurationValues.get( DIALECT ) );
}
private static boolean isNotNullAndNotEmpty(Object o) {
@ -502,7 +492,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
String databaseName,
String databaseVersion,
int databaseMajorVersion,
int databaseMinorVersion,
int databaseMinorVersion,
int databaseMicroVersion,
String driverName,
int driverMajorVersion,

View File

@ -45,7 +45,8 @@ public class MetadataAccessTests {
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 @@ public class MetadataAccessTests {
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 @@ public class MetadataAccessTests {
}
@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()) {