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 58c91f69d9..679827ebfd 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 @@ -104,13 +104,18 @@ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImpl protected ServiceBinding locateOrCreateServiceBinding(Class serviceRole, boolean checkParent) { ServiceBinding serviceBinding = locateServiceBinding( serviceRole, checkParent ); if ( serviceBinding == null ) { - R proxy = serviceProxyFactory.makeProxy( serviceRole ); - serviceBinding = new ServiceBinding( proxy ); - serviceBindingMap.put( serviceRole, serviceBinding ); + createServiceBinding( serviceRole ); } return serviceBinding; } + protected ServiceBinding createServiceBinding(Class serviceRole) { + R proxy = serviceProxyFactory.makeProxy( serviceRole ); + ServiceBinding serviceBinding = new ServiceBinding( proxy ); + serviceBindingMap.put( serviceRole, serviceBinding ); + return serviceBinding; + } + @Override public void registerService(Class serviceRole, R service) { ServiceBinding serviceBinding = locateOrCreateServiceBinding( serviceRole, false ); diff --git a/hibernate-core/src/main/java/org/hibernate/service/internal/BasicServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/service/internal/BasicServiceRegistryImpl.java index 5623092564..bb02d014e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/internal/BasicServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/internal/BasicServiceRegistryImpl.java @@ -23,7 +23,6 @@ */ package org.hibernate.service.internal; -import java.lang.reflect.Method; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,7 +36,6 @@ import org.hibernate.service.StandardServiceInitiators; import org.hibernate.service.UnknownServiceException; import org.hibernate.service.spi.BasicServiceInitiator; import org.hibernate.service.spi.Configurable; -import org.hibernate.service.spi.InjectService; import org.hibernate.service.spi.ServiceException; import org.hibernate.service.spi.ServiceRegistryAwareService; @@ -56,10 +54,15 @@ public class BasicServiceRegistryImpl extends AbstractServiceRegistryImpl implem this( StandardServiceInitiators.LIST, configurationValues ); } + @SuppressWarnings( {"unchecked"}) public BasicServiceRegistryImpl(List serviceInitiators, Map configurationValues) { super(); this.serviceInitiatorMap = toMap( serviceInitiators ); this.configurationValues = configurationValues; + for ( BasicServiceInitiator initiator : serviceInitiatorMap.values() ) { + // create the bindings up front to help identify to which registry services belong + createServiceBinding( initiator.getServiceInitiated() ); + } } /** @@ -87,6 +90,9 @@ public class BasicServiceRegistryImpl extends AbstractServiceRegistryImpl implem if ( serviceBinding != null ) { serviceBinding.setTarget( null ); } + else { + createServiceBinding( initiator.getServiceInitiated() ); + } final Object previous = serviceInitiatorMap.put( initiator.getServiceInitiated(), initiator ); if ( previous != null ) { LOG.debugf( "Over-wrote existing service initiator [role=%s]", initiator.getServiceInitiated().getName() );