Skip to content

Commit

Permalink
HHH-18079 Default to minimum supported DB version in more cases
Browse files Browse the repository at this point in the history
In particular when using hibernate.boot.allow_jdbc_metadata_access=false with jakarta.persistence.database-product-name
  • Loading branch information
yrodiere committed May 7, 2024
1 parent 3ce6a13 commit 1441504
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,7 @@ public JdbcEnvironment initiateService(Map<String, Object> configurationValues,
explicitDatabaseMinorVersion,
explicitDatabaseVersion);
}
else if ( explicitDialectConfiguration(
configurationValues,
explicitDatabaseName,
explicitDatabaseMajorVersion,
explicitDatabaseMinorVersion,
explicitDatabaseVersion) ) {
else if ( explicitDialectConfiguration( explicitDatabaseName, configurationValues ) ) {
return getJdbcEnvironmentWithExplicitConfiguration(
configurationValues,
registry,
Expand Down Expand Up @@ -394,14 +389,9 @@ private static void logDatabaseAndDriver(DatabaseMetaData dbmd) throws SQLExcept
}
}

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) {
Expand Down Expand Up @@ -502,7 +492,7 @@ public DialectResolutionInfoImpl(
String databaseName,
String databaseVersion,
int databaseMajorVersion,
int databaseMinorVersion,
int databaseMinorVersion,
int databaseMicroVersion,
String driverName,
int driverMajorVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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()) {
Expand Down

0 comments on commit 1441504

Please sign in to comment.