log warnings when settings are ignored for Datasource

This commit is contained in:
Gavin King 2024-12-10 21:44:09 +01:00
parent 0531454f88
commit 6cfcee5e4b
3 changed files with 18 additions and 4 deletions

View File

@ -291,7 +291,7 @@ public interface JdbcSettings extends C3p0Settings, AgroalSettings, HikariCPSett
*
* @since 5.2.10
*/
String CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT= "hibernate.connection.provider_disables_autocommit";
String CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT = "hibernate.connection.provider_disables_autocommit";
/**
* A prefix for properties specifying arbitrary JDBC connection properties. These

View File

@ -16,6 +16,7 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
import org.hibernate.engine.jndi.spi.JndiService;
import org.hibernate.internal.log.ConnectionInfoLogger;
import org.hibernate.service.UnknownUnwrapTypeException;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.InjectService;
@ -87,8 +88,8 @@ public class DatasourceConnectionProviderImpl implements ConnectionProvider, Con
public void configure(Map<String, Object> configValues) {
if ( dataSource == null ) {
final Object dataSourceSetting = configValues.get( DATASOURCE );
if ( dataSourceSetting instanceof DataSource ) {
dataSource = (DataSource) dataSourceSetting;
if ( dataSourceSetting instanceof DataSource ds ) {
dataSource = ds;
}
else {
final String dataSourceJndiName = (String) dataSourceSetting;
@ -109,6 +110,15 @@ public class DatasourceConnectionProviderImpl implements ConnectionProvider, Con
throw new HibernateException( "Unable to determine appropriate DataSource to use" );
}
if ( configValues.containsKey( AvailableSettings.AUTOCOMMIT ) ) {
ConnectionInfoLogger.INSTANCE.ignoredSetting( AvailableSettings.AUTOCOMMIT,
DatasourceConnectionProviderImpl.class );
}
if ( configValues.containsKey( AvailableSettings.ISOLATION ) ) {
ConnectionInfoLogger.INSTANCE.ignoredSetting( AvailableSettings.ISOLATION,
DatasourceConnectionProviderImpl.class );
}
user = (String) configValues.get( AvailableSettings.USER );
pass = (String) configValues.get( AvailableSettings.PASS );
useCredentials = user != null || pass != null;

View File

@ -49,7 +49,7 @@ public interface ConnectionInfoLogger extends BasicLogger {
@Message(id = 10001006,
value = "No JDBC Driver class was specified by property '"
+ JdbcSettings.JAKARTA_JDBC_DRIVER + "', '"
+ JdbcSettings.JPA_JDBC_DRIVER + "', or '"
+ JdbcSettings.JPA_JDBC_DRIVER + "', or '"
+ JdbcSettings.DRIVER + "'")
void jdbcDriverNotSpecified();
@ -72,4 +72,8 @@ public interface ConnectionInfoLogger extends BasicLogger {
@LogMessage(level = DEBUG)
@Message(value = "Configuring connection pool [%s]", id = 10001012)
void configureConnectionPool(String type);
@LogMessage(level = INFO)
@Message(value = "Ignoring setting '%s' for connection provider [%s]", id = 10001013)
void ignoredSetting(String setting, Class<?> provider);
}