HHH-12396 - Fix problem with EnumType resolution on GlassFish platforms.

This commit is contained in:
Chris Cranford 2018-05-31 22:43:43 -04:00
parent 19d59dac71
commit 736c913f14
2 changed files with 34 additions and 9 deletions

View File

@ -10,7 +10,8 @@ import java.io.Serializable;
import java.util.Properties;
import org.hibernate.MappingException;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.UserType;
@ -24,11 +25,11 @@ import org.hibernate.usertype.UserType;
*/
@Deprecated
public class TypeResolver implements Serializable {
private final BasicTypeRegistry basicTypeRegistry;
private final TypeFactory typeFactory;
private final TypeConfiguration typeConfiguration;
public TypeResolver(TypeConfiguration typeConfiguration, TypeFactory typeFactory){
this.basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
this.typeConfiguration = typeConfiguration;
this.typeFactory = typeFactory;
}
@ -51,15 +52,15 @@ public class TypeResolver implements Serializable {
// }
public void registerTypeOverride(BasicType type) {
basicTypeRegistry.register( type );
typeConfiguration.getBasicTypeRegistry().register( type );
}
public void registerTypeOverride(UserType type, String[] keys) {
basicTypeRegistry.register( type, keys );
typeConfiguration.getBasicTypeRegistry().register( type, keys );
}
public void registerTypeOverride(CompositeUserType type, String[] keys) {
basicTypeRegistry.register( type, keys );
typeConfiguration.getBasicTypeRegistry().register( type, keys );
}
public TypeFactory getTypeFactory() {
@ -74,7 +75,7 @@ public class TypeResolver implements Serializable {
* @return The registered type
*/
public BasicType basic(String name) {
return basicTypeRegistry.getRegisteredType( name );
return typeConfiguration.getBasicTypeRegistry().getRegisteredType( name );
}
/**
@ -119,12 +120,13 @@ public class TypeResolver implements Serializable {
}
try {
Class typeClass = ReflectHelper.classForName( typeName );
final ClassLoaderService classLoaderService = typeConfiguration.getServiceRegistry().getService( ClassLoaderService.class );
Class typeClass = classLoaderService.classForName( typeName );
if ( typeClass != null ) {
return typeFactory.byClass( typeClass, parameters );
}
}
catch ( ClassNotFoundException ignore ) {
catch ( ClassLoadingException ignore ) {
}
return null;

View File

@ -25,6 +25,7 @@ import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.SessionFactoryRegistry;
import org.hibernate.metamodel.internal.MetamodelImpl;
import org.hibernate.metamodel.spi.MetamodelImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.Type;
import org.hibernate.type.TypeFactory;
@ -174,6 +175,18 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
return scope.getSessionFactory();
}
/**
* Obtain the ServiceRegistry scoped to the TypeConfiguration.
*
* @apiNote Depending on what the {@link Scope} is currently scoped to will determine where the
* {@link ServiceRegistry} is obtained from.
*
* @return The ServiceRegistry
*/
public ServiceRegistry getServiceRegistry() {
return scope.getServiceRegistry();
}
@Override
public void sessionFactoryCreated(SessionFactory factory) {
// Instead of allowing scope#setSessionFactory to influence this, we use the SessionFactoryObserver callback
@ -237,6 +250,16 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
return metadataBuildingContext;
}
public ServiceRegistry getServiceRegistry() {
if ( metadataBuildingContext != null ) {
return metadataBuildingContext.getBootstrapContext().getServiceRegistry();
}
else if ( sessionFactory != null ) {
return sessionFactory.getServiceRegistry();
}
return null;
}
public void setMetadataBuildingContext(MetadataBuildingContext metadataBuildingContext) {
this.metadataBuildingContext = metadataBuildingContext;
}