HHH-10365: Initializing ClassLoaderService in OsgiPersistenceProvider.

This commit is contained in:
Kankare Timo 2016-03-11 12:35:23 +02:00 committed by Brett Meyer
parent bf9b3f524d
commit 585a8aa757
3 changed files with 36 additions and 5 deletions

View File

@ -43,6 +43,7 @@ import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.boot.spi.MetadataBuilderImplementor;
@ -165,7 +166,15 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
PersistenceUnitDescriptor persistenceUnit,
Map integrationSettings,
ClassLoader providedClassLoader ) {
this(persistenceUnit,integrationSettings,providedClassLoader,null);
}
public EntityManagerFactoryBuilderImpl(
PersistenceUnitDescriptor persistenceUnit,
Map integrationSettings,
ClassLoader providedClassLoader,
ClassLoaderService providedClassLoaderService) {
LogHelper.logPersistenceUnitInformation( persistenceUnit );
this.persistenceUnit = persistenceUnit;
@ -175,7 +184,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
// Build the boot-strap service registry, which mainly handles class loader interactions
final BootstrapServiceRegistry bsr = buildBootstrapServiceRegistry( integrationSettings, providedClassLoader );
final BootstrapServiceRegistry bsr = buildBootstrapServiceRegistry( integrationSettings, providedClassLoader, providedClassLoaderService);
// merge configuration sources and build the "standard" service registry
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder( bsr );
@ -312,8 +321,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
*/
private BootstrapServiceRegistry buildBootstrapServiceRegistry(
Map integrationSettings,
ClassLoader providedClassLoader) {
ClassLoader providedClassLoader,
ClassLoaderService providedClassLoaderService) {
final BootstrapServiceRegistryBuilder bsrBuilder = new BootstrapServiceRegistryBuilder();
if (providedClassLoaderService != null) {
bsrBuilder.applyClassLoaderService(providedClassLoaderService);
}
bsrBuilder.applyIntegrator( new JpaIntegrator() );
final IntegratorProvider integratorProvider = (IntegratorProvider) integrationSettings.get( INTEGRATOR_PROVIDER );

View File

@ -9,6 +9,7 @@ package org.hibernate.jpa.boot.spi;
import java.util.Map;
import javax.persistence.spi.PersistenceUnitInfo;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor;
@ -27,6 +28,7 @@ public final class Bootstrap {
Map integration) {
return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration );
}
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitDescriptor persistenceUnitDescriptor,
Map integration,
@ -34,6 +36,14 @@ public final class Bootstrap {
return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, providedClassLoader );
}
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitDescriptor persistenceUnitDescriptor,
Map integration,
ClassLoader providedClassLoader,
ClassLoaderService providedClassLoaderService) {
return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, providedClassLoader, providedClassLoaderService );
}
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitInfo persistenceUnitInfo,
Map integration) {
@ -46,4 +56,12 @@ public final class Bootstrap {
ClassLoader providedClassLoader) {
return getEntityManagerFactoryBuilder( new PersistenceUnitInfoDescriptor( persistenceUnitInfo ), integration, providedClassLoader );
}
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
PersistenceUnitInfo persistenceUnitInfo,
Map integration,
ClassLoader providedClassLoader,
ClassLoaderService providedClassLoaderService) {
return getEntityManagerFactoryBuilder( new PersistenceUnitInfoDescriptor( persistenceUnitInfo ), integration, providedClassLoader, providedClassLoaderService );
}
}

View File

@ -91,8 +91,8 @@ public class OsgiPersistenceProvider extends HibernatePersistenceProvider {
);
osgiClassLoader.addClassLoader( info.getClassLoader() );
return Bootstrap.getEntityManagerFactoryBuilder( info, settings, osgiClassLoader ).build();
return Bootstrap.getEntityManagerFactoryBuilder( info, settings, osgiClassLoader, new OSGiClassLoaderServiceImpl( osgiClassLoader, osgiServiceUtil ) ).build();
}
@SuppressWarnings("unchecked")