diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 8258c836b4..04ee109fbb 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -294,6 +294,7 @@ public final class SessionFactoryImpl for ( Integrator integrator : integrators ) { integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry ); } + integrators.clear(); } } @@ -715,6 +716,7 @@ public final class SessionFactoryImpl for ( Integrator integrator : integrators ) { integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry ); } + integrators.clear(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/service/classloading/internal/ClassLoaderServiceImpl.java b/hibernate-core/src/main/java/org/hibernate/service/classloading/internal/ClassLoaderServiceImpl.java index 6d680a0d95..aa1bafd11c 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/classloading/internal/ClassLoaderServiceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/classloading/internal/ClassLoaderServiceImpl.java @@ -33,6 +33,7 @@ import java.util.Enumeration; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.ServiceLoader; @@ -52,6 +53,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class ); private final ClassLoader aggregatedClassLoader; + private final LinkedList loaders = new LinkedList(); public ClassLoaderServiceImpl() { this( ClassLoaderServiceImpl.class.getClassLoader() ); @@ -231,14 +233,23 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { @Override public LinkedHashSet loadJavaServices(Class serviceContract) { - final ServiceLoader loader = ServiceLoader.load( serviceContract, aggregatedClassLoader ); - final LinkedHashSet services = new LinkedHashSet(); - for ( S service : loader ) { + ServiceLoader serviceLoader = ServiceLoader.load( serviceContract, aggregatedClassLoader ); + final LinkedHashSet services = new LinkedHashSet(); + for ( S service : serviceLoader) { services.add( service ); } - + loaders.add(serviceLoader); return services; } + + @Override + public void stop() { + while (!loaders.isEmpty()){ + ServiceLoader loader = loaders.removeLast(); + loader.reload();//clear service loader providers + } + } + private static class AggregatedClassLoader extends ClassLoader { private final ClassLoader[] individualClassLoaders; diff --git a/hibernate-core/src/main/java/org/hibernate/service/classloading/spi/ClassLoaderService.java b/hibernate-core/src/main/java/org/hibernate/service/classloading/spi/ClassLoaderService.java index 5bbd2a0555..d13fb71adf 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/classloading/spi/ClassLoaderService.java +++ b/hibernate-core/src/main/java/org/hibernate/service/classloading/spi/ClassLoaderService.java @@ -29,13 +29,14 @@ import java.util.LinkedHashSet; import java.util.List; import org.hibernate.service.Service; +import org.hibernate.service.spi.Stoppable; /** * A service for interacting with class loaders * * @author Steve Ebersole */ -public interface ClassLoaderService extends Service { +public interface ClassLoaderService extends Service, Stoppable { /** * Locate a class by name * diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/event/JpaIntegrator.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/event/JpaIntegrator.java index 78250d8e28..916a435286 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/event/JpaIntegrator.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/event/JpaIntegrator.java @@ -57,18 +57,7 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry; * @author Steve Ebersole */ public class JpaIntegrator implements Integrator { - private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new DuplicationStrategy() { - @Override - public boolean areMatch(Object listener, Object original) { - return listener.getClass().equals( original.getClass() ) && - HibernateEntityManagerEventListener.class.isInstance( original ); - } - - @Override - public Action getAction() { - return Action.KEEP_ORIGINAL; - } - }; + private static final DuplicationStrategy JPA_DUPLICATION_STRATEGY = new JPADuplicationStrategy(); private static final DuplicationStrategy JACC_DUPLICATION_STRATEGY = new DuplicationStrategy() { @Override @@ -260,4 +249,17 @@ public class JpaIntegrator implements Integrator { throw new HibernateException( "Could not instantiate requested listener [" + listenerImpl + "]", e ); } } + + private static class JPADuplicationStrategy implements DuplicationStrategy { + @Override + public boolean areMatch(Object listener, Object original) { + return listener.getClass().equals( original.getClass() ) && + HibernateEntityManagerEventListener.class.isInstance( original ); + } + + @Override + public Action getAction() { + return Action.KEEP_ORIGINAL; + } + } }