diff --git a/hibernate-core/src/main/java/org/hibernate/type/TypeFactory.java b/hibernate-core/src/main/java/org/hibernate/type/TypeFactory.java index 9acb4bc484a5..1c82b314d1ac 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/TypeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/type/TypeFactory.java @@ -17,6 +17,7 @@ import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.ReflectHelper; +import org.hibernate.service.ServiceRegistry; import org.hibernate.tuple.component.ComponentMetamodel; import org.hibernate.type.spi.TypeBootstrapContext; import org.hibernate.type.spi.TypeConfiguration; @@ -94,15 +95,24 @@ public Type type(Class typeClass, Properties parameters) { try { final Type type; - final Constructor bootstrapContextAwareTypeConstructor = ReflectHelper.getConstructor( + Constructor contextAwareTypeConstructor = ReflectHelper.getConstructor( typeClass, - TypeBootstrapContext.class + ServiceRegistry.class ); - if ( bootstrapContextAwareTypeConstructor != null ) { - type = bootstrapContextAwareTypeConstructor.newInstance( this ); + if ( contextAwareTypeConstructor != null ) { + type = contextAwareTypeConstructor.newInstance( this.typeConfiguration.getServiceRegistry() ); } else { - type = typeClass.newInstance(); + contextAwareTypeConstructor = ReflectHelper.getConstructor( + typeClass, + TypeBootstrapContext.class + ); + if ( contextAwareTypeConstructor != null ) { + type = contextAwareTypeConstructor.newInstance( this ); + } + else { + type = typeClass.newInstance(); + } } injectParameters( type, parameters ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/contributor/ArrayType.java b/hibernate-core/src/test/java/org/hibernate/test/type/contributor/ArrayType.java index e5e4328bd160..15738d6b8382 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/contributor/ArrayType.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/contributor/ArrayType.java @@ -3,10 +3,11 @@ import java.util.Map; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.config.spi.ConfigurationService; +import org.hibernate.service.ServiceRegistry; import org.hibernate.type.AbstractSingleColumnStandardBasicType; import org.hibernate.type.DiscriminatorType; import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor; -import org.hibernate.type.spi.TypeBootstrapContext; /** * @author Vlad Mihalcea @@ -23,9 +24,10 @@ public ArrayType() { super( VarcharTypeDescriptor.INSTANCE, ArrayTypeDescriptor.INSTANCE ); } - public ArrayType(TypeBootstrapContext typeBootstrapContext) { + public ArrayType(ServiceRegistry serviceRegistry) { super( VarcharTypeDescriptor.INSTANCE, ArrayTypeDescriptor.INSTANCE ); - this.settings = typeBootstrapContext.getConfigurationSettings(); + ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class ); + this.settings = configurationService.getSettings(); } @Override