HHH-17463 UnsupportedOperationException when using JAKARTA_JDBC_URL

This commit is contained in:
Andrea Boriero 2023-12-11 15:26:13 +01:00 committed by Christian Beikov
parent d5bde15aaa
commit d90d6e63f0
1 changed files with 36 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import java.util.Map;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.service.Service;
import org.hibernate.service.internal.AbstractServiceRegistryImpl;
import org.hibernate.service.internal.ProvidedService;
@ -35,7 +36,7 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
BootstrapServiceRegistry bootstrapServiceRegistry,
Map<String,Object> configurationValues) {
super( bootstrapServiceRegistry, autoCloseRegistry );
this.configurationValues = configurationValues;
this.configurationValues = normalize( configurationValues);
}
/**
@ -141,4 +142,38 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
super.destroy();
this.configurationValues = null;
}
private static Map<String, Object> normalize(Map<String, Object> configurationValues) {
final Object jdbcUrl = configurationValues.get( AvailableSettings.JAKARTA_JDBC_URL );
if ( jdbcUrl != null ) {
configurationValues.putIfAbsent( AvailableSettings.URL, jdbcUrl );
}
final Object username = configurationValues.get( AvailableSettings.JAKARTA_JDBC_USER );
if ( username != null ) {
configurationValues.putIfAbsent( AvailableSettings.USER, username );
}
final Object password = configurationValues.get( AvailableSettings.JAKARTA_JDBC_PASSWORD );
if ( password != null ) {
configurationValues.putIfAbsent( AvailableSettings.PASS, password );
}
final Object driver = configurationValues.get( AvailableSettings.JAKARTA_JDBC_DRIVER );
if ( driver != null ) {
configurationValues.putIfAbsent( AvailableSettings.DRIVER, driver );
}
final Object nonJtaDatasource = configurationValues.get( AvailableSettings.JAKARTA_NON_JTA_DATASOURCE );
if ( nonJtaDatasource != null ) {
configurationValues.putIfAbsent( AvailableSettings.DATASOURCE, nonJtaDatasource );
}
final Object jtaDatasource = configurationValues.get( AvailableSettings.JAKARTA_JTA_DATASOURCE );
if ( jtaDatasource != null ) {
configurationValues.putIfAbsent( AvailableSettings.DATASOURCE, jtaDatasource );
}
return configurationValues;
}
}