HHH-9446 - ClassCastException on loaded entities under GlassFish 4.0
This commit is contained in:
parent
d5d066cb3d
commit
e9230758b4
|
@ -42,6 +42,7 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.internal.util.ClassLoaderHelper;
|
import org.hibernate.internal.util.ClassLoaderHelper;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -355,66 +356,4 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
// completely temporary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform some discrete work with with the TCCL set to our aggregated ClassLoader
|
|
||||||
*
|
|
||||||
* @param work The discrete work to be done
|
|
||||||
* @param <T> The type of the work result
|
|
||||||
*
|
|
||||||
* @return The work result.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public <T> T withTccl(Work<T> work) {
|
|
||||||
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
|
|
||||||
|
|
||||||
boolean set = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.currentThread().setContextClassLoader(
|
|
||||||
new TcclSafeAggregatedClassLoader( aggregatedClassLoader, tccl ) );
|
|
||||||
set = true;
|
|
||||||
}
|
|
||||||
catch (Exception ignore) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return work.perform();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if ( set ) {
|
|
||||||
Thread.currentThread().setContextClassLoader( tccl );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove in ORM 5! See HHH-8818
|
|
||||||
private class TcclSafeAggregatedClassLoader extends ClassLoader {
|
|
||||||
private final AggregatedClassLoader aggregatedClassLoader;
|
|
||||||
|
|
||||||
private TcclSafeAggregatedClassLoader(AggregatedClassLoader aggregatedClassLoader, ClassLoader tccl) {
|
|
||||||
super(tccl);
|
|
||||||
this.aggregatedClassLoader = aggregatedClassLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Enumeration<URL> getResources(String name) throws IOException {
|
|
||||||
return aggregatedClassLoader.getResources( name );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected URL findResource(String name) {
|
|
||||||
return aggregatedClassLoader.findResource( name );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
|
||||||
return aggregatedClassLoader.findClass( name );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,31 +88,4 @@ public interface ClassLoaderService extends Service, Stoppable {
|
||||||
* @return The ordered set of discovered services.
|
* @return The ordered set of discovered services.
|
||||||
*/
|
*/
|
||||||
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract);
|
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hack around continued (temporary) need to sometimes set the TCCL for code we call that expects it.
|
|
||||||
*
|
|
||||||
* @param <T> The result type
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static interface Work<T> {
|
|
||||||
/**
|
|
||||||
* The work to be performed with the TCCL set
|
|
||||||
*
|
|
||||||
* @return The result of the work
|
|
||||||
*/
|
|
||||||
public T perform();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform some discrete work with with the TCCL set to our aggregated ClassLoader
|
|
||||||
*
|
|
||||||
* @param work The discrete work to be done
|
|
||||||
* @param <T> The type of the work result
|
|
||||||
*
|
|
||||||
* @return The work result.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public <T> T withTccl(Work<T> work);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,6 @@ import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
|
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
|
||||||
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
|
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
|
||||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
|
@ -195,22 +193,11 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
this.standardServiceRegistry = ssrBuilder.build();
|
this.standardServiceRegistry = ssrBuilder.build();
|
||||||
configure( standardServiceRegistry, mergedSettings );
|
configure( standardServiceRegistry, mergedSettings );
|
||||||
|
|
||||||
// Build the Metadata object
|
final MetadataSources metadataSources = new MetadataSources( bsr );
|
||||||
// NOTE : because we still use hibernate-commons-annotations, we still need to
|
List<AttributeConverterDefinition> attributeConverterDefinitions = populate( metadataSources, mergedSettings, standardServiceRegistry );
|
||||||
// use the TCCL hacks because hibernate-commons-annotations uses TCCL
|
final MetadataBuilder metamodelBuilder = metadataSources.getMetadataBuilder( standardServiceRegistry );
|
||||||
final ClassLoaderService classLoaderService = bsr.getService( ClassLoaderService.class );
|
populate( metamodelBuilder, mergedSettings, standardServiceRegistry, attributeConverterDefinitions );
|
||||||
this.metadata = ( (ClassLoaderServiceImpl) classLoaderService ).withTccl(
|
this.metadata = (MetadataImplementor) metamodelBuilder.build();
|
||||||
new ClassLoaderServiceImpl.Work<MetadataImplementor>() {
|
|
||||||
@Override
|
|
||||||
public MetadataImplementor perform() {
|
|
||||||
final MetadataSources metadataSources = new MetadataSources( bsr );
|
|
||||||
List<AttributeConverterDefinition> attributeConverterDefinitions = populate( metadataSources, mergedSettings, standardServiceRegistry );
|
|
||||||
final MetadataBuilder metamodelBuilder = metadataSources.getMetadataBuilder( standardServiceRegistry );
|
|
||||||
populate( metamodelBuilder, mergedSettings, standardServiceRegistry, attributeConverterDefinitions );
|
|
||||||
return (MetadataImplementor) metamodelBuilder.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
withValidatorFactory( configurationValues.get( AvailableSettings.VALIDATION_FACTORY ) );
|
withValidatorFactory( configurationValues.get( AvailableSettings.VALIDATION_FACTORY ) );
|
||||||
|
|
||||||
|
|
|
@ -120,16 +120,7 @@ public class EnversServiceImpl implements EnversService, Configurable, Stoppable
|
||||||
|
|
||||||
this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
||||||
|
|
||||||
// NOTE : we use the TCCL here for hibernate-commons-annotations
|
doInitialize( metadata, mappingCollector, serviceRegistry, classLoaderService );
|
||||||
classLoaderService.withTccl(
|
|
||||||
new ClassLoaderService.Work<Void>() {
|
|
||||||
@Override
|
|
||||||
public Void perform() {
|
|
||||||
doInitialize( metadata, mappingCollector, serviceRegistry, classLoaderService );
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doInitialize(
|
private void doInitialize(
|
||||||
|
|
Loading…
Reference in New Issue