diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/BasicConnectionCreator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/BasicConnectionCreator.java index ff3bcceb3a..00bb69cb4f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/BasicConnectionCreator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/BasicConnectionCreator.java @@ -124,4 +124,13 @@ public abstract class BasicConnectionCreator implements ConnectionCreator { } protected abstract Connection makeConnection(String url, Properties connectionProps); + + /** + * Exposed for testing purposes only. + * @return + */ + public Properties getConnectionProperties() { + return new Properties( connectionProps ); + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/ConnectionProviderInitiator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/ConnectionProviderInitiator.java index 6f7978cc83..c6a25525ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/ConnectionProviderInitiator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/ConnectionProviderInitiator.java @@ -417,6 +417,7 @@ public class ConnectionProviderInitiator implements StandardServiceInitiator(); ISOLATION_VALUE_MAP.put( "TRANSACTION_NONE", Connection.TRANSACTION_NONE ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java index c49e118db8..b108bbb5a7 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java @@ -215,6 +215,16 @@ public class DriverManagerConnectionProviderImpl } //CHECKSTYLE:END_ALLOW_FINALIZER + /** + * Exposed to facilitate testing only. + * @return + */ + public Properties getConnectionProperties() { + BasicConnectionCreator connectionCreator = (BasicConnectionCreator) this.state.pool.connectionCreator; + return connectionCreator.getConnectionProperties(); + } + + public static class PooledConnections { private final ConcurrentLinkedQueue allConnections = new ConcurrentLinkedQueue(); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/connection/TestConnectionPool.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/connection/TestConnectionPool.java index cc8e176c80..cd091721c1 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/connection/TestConnectionPool.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/connection/TestConnectionPool.java @@ -7,6 +7,7 @@ package org.hibernate.jpa.test.connection; import java.util.Map; +import java.util.Properties; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.Id; @@ -15,10 +16,13 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.exception.SQLGrammarException; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.TestForIssue; +import org.junit.Assert; import org.junit.Test; /** @@ -46,6 +50,19 @@ public class TestConnectionPool AvailableSettings.POOL_SIZE, Integer.valueOf( CONNECTION_POOL_SIZE ) ); + options.put( "hibernate.connection.customProperty", "x" ); + options.put( AvailableSettings.CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT, "true" ); + } + + @Test + @TestForIssue(jiraKey = "HHH-13700") + public void testConnectionPoolPropertyFiltering() { + ConnectionProvider cp = serviceRegistry().getService( ConnectionProvider.class ); + DriverManagerConnectionProviderImpl dmcp = (DriverManagerConnectionProviderImpl) cp; + Properties connectionProperties = dmcp.getConnectionProperties(); + Assert.assertEquals( "x", connectionProperties.getProperty( "customProperty" ) ); + Assert.assertNull( connectionProperties.getProperty( "pool_size" ) ); + Assert.assertNull( connectionProperties.getProperty( "provider_disables_autocommit" ) ); } @Test