HHH-9887 - Make sure the JPA temp ClassLoader is not used to load Class definitions that are then held on to

This commit is contained in:
Steve Ebersole 2015-07-02 15:47:08 -05:00
parent 0d6393a8b1
commit 9b5bb9751c
4 changed files with 37 additions and 45 deletions

View File

@ -53,6 +53,7 @@ import org.hibernate.boot.spi.MappingDefaults;
import org.hibernate.boot.spi.MetadataBuilderImplementor;
import org.hibernate.boot.spi.MetadataBuilderInitializer;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.boot.spi.MetadataSourcesContributor;
import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cache.spi.access.AccessType;
@ -385,7 +386,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
// }
@Override
public MetadataImpl build() {
public MetadataImplementor build() {
final CfgXmlAccessService cfgXmlAccessService = options.serviceRegistry.getService( CfgXmlAccessService.class );
if ( cfgXmlAccessService.getAggregatedConfig() != null ) {
if ( cfgXmlAccessService.getAggregatedConfig().getMappingReferences() != null ) {

View File

@ -1,38 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.boot.model.process.internal;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.process.spi.ManagedResources;
import org.hibernate.boot.spi.MetadataBuildingOptions;
/**
* @author Steve Ebersole
*/
public class ManagedResourcesBuilder {
/**
* Singleton access
*/
public static final ManagedResourcesBuilder INSTANCE = new ManagedResourcesBuilder();
private ManagedResourcesBuilder() {
}
public ManagedResources buildCompleteManagedResources(
final MetadataSources sources,
final MetadataBuildingOptions options) {
// Instantiate ManagedResourcesImpl, and build its baseline from MetadataSources
final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( sources, options );
ScanningCoordinator.INSTANCE.coordinateScan( managedResources, options, sources.getXmlMappingBinderAccess() );
return managedResources;
}
}

View File

@ -13,13 +13,12 @@ import java.util.Set;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.internal.ClassLoaderAccessImpl;
import org.hibernate.boot.internal.InFlightMetadataCollectorImpl;
import org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl;
import org.hibernate.boot.internal.MetadataBuildingContextRootImpl;
import org.hibernate.boot.internal.MetadataImpl;
import org.hibernate.boot.jaxb.internal.MappingBinder;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.TypeContributor;
import org.hibernate.boot.model.process.internal.ManagedResourcesBuilder;
import org.hibernate.boot.model.process.internal.ManagedResourcesImpl;
import org.hibernate.boot.model.process.internal.ScanningCoordinator;
import org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl;
import org.hibernate.boot.model.source.internal.hbm.EntityHierarchyBuilder;
import org.hibernate.boot.model.source.internal.hbm.EntityHierarchySourceImpl;
@ -32,6 +31,7 @@ import org.hibernate.boot.spi.AdditionalJaxbMappingProducer;
import org.hibernate.boot.spi.ClassLoaderAccess;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.boot.spi.MetadataContributor;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AttributeConverterDefinition;
import org.hibernate.cfg.MetadataSourceType;
import org.hibernate.dialect.Dialect;
@ -67,19 +67,45 @@ import org.jboss.logging.Logger;
public class MetadataBuildingProcess {
private static final Logger log = Logger.getLogger( MetadataBuildingProcess.class );
public static MetadataImpl build(
/**
* Unified single phase for MetadataSources->Metadata process
*
* @param sources The MetadataSources
* @param options The building options
*
* @return The built Metadata
*/
public static MetadataImplementor build(
final MetadataSources sources,
final MetadataBuildingOptions options) {
return complete( prepare( sources, options ), options );
}
/**
* First step of 2-phase for MetadataSources->Metadata process
*
* @param sources The MetadataSources
* @param options The building options
*
* @return Token/memento representing all known users resources (classes, packages, mapping files, etc).
*/
public static ManagedResources prepare(
final MetadataSources sources,
final MetadataBuildingOptions options) {
return ManagedResourcesBuilder.INSTANCE.buildCompleteManagedResources( sources, options );
final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( sources, options );
ScanningCoordinator.INSTANCE.coordinateScan( managedResources, options, sources.getXmlMappingBinderAccess() );
return managedResources;
}
public static MetadataImpl complete(final ManagedResources managedResources, final MetadataBuildingOptions options) {
/**
* Second step of 2-phase for MetadataSources->Metadata process
*
* @param managedResources The token/memento from 1st phase
* @param options The building options
*
* @return Token/memento representing all known users resources (classes, packages, mapping files, etc).
*/
public static MetadataImplementor complete(final ManagedResources managedResources, final MetadataBuildingOptions options) {
final BasicTypeRegistry basicTypeRegistry = handleTypes( options );
final InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl(

View File

@ -205,6 +205,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
if ( useClassTransformer ) {
persistenceUnit.pushClassTransformer( managedResources.getAnnotatedClassNames() );
}
// for the time being we want to revoke access to the temp ClassLoader if one was passed
metamodelBuilder.applyTempClassLoader( null );
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~