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

HHH-18079 Default to minimum supported DB version when using hibernate.boot.allow_jdbc_metadata_access=false with jakarta.persistence.database-product-name #8326

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading