From 70bd57bcff7c906a97f4617124b28d3b5865aa84 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Wed, 2 Nov 2011 17:37:05 +0800 Subject: [PATCH] HHH-6792 connection leaks due to service registry is not destroyed --- .../org/hibernate/engine/jdbc/internal/JdbcServicesImpl.java | 4 ++-- .../service/internal/AbstractServiceRegistryImpl.java | 2 +- .../hibernate/testing/junit4/BaseCoreFunctionalTestCase.java | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcServicesImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcServicesImpl.java index 3ca4490751..b164f9574a 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcServicesImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcServicesImpl.java @@ -229,7 +229,7 @@ public class JdbcServicesImpl implements JdbcServices, ServiceRegistryAwareServi @Override public void releaseConnection(Connection connection) throws SQLException { - connection.close(); + connectionProvider.closeConnection( connection ); } } @@ -247,7 +247,7 @@ public class JdbcServicesImpl implements JdbcServices, ServiceRegistryAwareServi @Override public void releaseConnection(Connection connection) throws SQLException { - connection.close(); + connectionProvider.releaseAnyConnection( connection ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java index d446bfb563..2822492d45 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java @@ -252,7 +252,7 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl ); } } - + @Override public void destroy() { ListIterator serviceIterator = serviceList.listIterator( serviceList.size() ); while ( serviceIterator.hasPrevious() ) { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index 1d59d42fde..f5e05f9a34 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -365,6 +365,11 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { sessionFactory.close(); sessionFactory = null; configuration = null; + if(serviceRegistry == null){ + return; + } + serviceRegistry.destroy(); + serviceRegistry=null; } @OnFailure