diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java index f819e57603..7ea19fc69e 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java @@ -403,4 +403,9 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor, public List> findEntityGraphsByType(Class entityClass) { return delegate.findEntityGraphsByType(entityClass); } + + @Override + public Class classForName(String className) { + return delegate.classForName( className ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java index 8adb4fdcc1..e26492aca9 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java @@ -111,7 +111,6 @@ public interface SessionFactoryImplementor * * @return The factory's ServiceRegistry */ - @Override ServiceRegistryImplementor getServiceRegistry(); /** diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 7d2ffe7b2e..724b8711bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -458,8 +458,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im private static SessionFactoryServiceRegistry getServiceRegistry( SessionFactoryOptions options, SessionFactoryImplementor self) { - return options - .getServiceRegistry() + return options.getServiceRegistry() .requireService( SessionFactoryServiceRegistryFactory.class ) // it is not great how we pass in an instance to // an incompletely-initialized instance here: @@ -1704,6 +1703,12 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im return schemaManager; } + @Override + public Class classForName(String className) { + return serviceRegistry.requireService( ClassLoaderService.class ) + .classForName( className ); + } + private enum Status { OPEN, CLOSING, diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java index e93f4d4cbd..b4d5fcb7c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java @@ -13,7 +13,6 @@ import java.util.List; import java.util.function.Function; import org.checkerframework.checker.nullness.qual.Nullable; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.query.criteria.JpaSelection; @@ -69,8 +68,6 @@ public class FullyQualifiedReflectivePathTerminal private Function, ?> resolveTerminalSemantic() { return semanticQueryWalker -> { final SqmCreationContext creationContext = creationState.getCreationContext(); - final ClassLoaderService cls = - creationContext.getServiceRegistry().requireService( ClassLoaderService.class ); final String fullPath = getFullPath(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -85,7 +82,7 @@ public class FullyQualifiedReflectivePathTerminal // See if it is a Class FQN try { - final Class namedClass = cls.classForName( fullPath ); + final Class namedClass = creationContext.classForName( fullPath ); if ( namedClass != null ) { return semanticQueryWalker.visitFullyQualifiedClass( namedClass ); } @@ -99,7 +96,7 @@ public class FullyQualifiedReflectivePathTerminal final String parentFullPath = getParent().getFullPath(); try { - final Class namedClass = cls.classForName( parentFullPath ); + final Class namedClass = creationContext.classForName( parentFullPath ); if ( namedClass != null ) { return createEnumOrFieldLiteral( namedClass ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index c60e3d3cbd..4173f80d59 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -32,7 +32,6 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.dialect.function.SqlColumn; import org.hibernate.grammars.hql.HqlLexer; @@ -1553,17 +1552,12 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem } private JavaType resolveInstantiationTargetJtd(String className) { - final Class targetJavaType = classForName( creationContext.getJpaMetamodel().qualifyImportableName( className ) ); - return creationContext.getJpaMetamodel() - .getTypeConfiguration() - .getJavaTypeRegistry() + final String qualifiedName = creationContext.getJpaMetamodel().qualifyImportableName( className ); + final Class targetJavaType = creationContext.classForName( qualifiedName ); + return creationContext.getTypeConfiguration().getJavaTypeRegistry() .resolveDescriptor( targetJavaType ); } - private Class classForName(String className) { - return creationContext.getServiceRegistry().requireService( ClassLoaderService.class ).classForName( className ); - } - @Override public SqmDynamicInstantiationArgument visitInstantiationArgument(HqlParser.InstantiationArgumentContext ctx) { final HqlParser.VariableContext variable = ctx.variable(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/SqmCreationContext.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/SqmCreationContext.java index ec67e5a236..ecba1dde60 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/SqmCreationContext.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/SqmCreationContext.java @@ -10,7 +10,6 @@ import org.hibernate.Incubating; import org.hibernate.query.BindingContext; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.service.ServiceRegistry; /** * The context in which all SQM creations occur. @@ -25,7 +24,10 @@ public interface SqmCreationContext extends BindingContext { return getQueryEngine().getCriteriaBuilder(); } - default ServiceRegistry getServiceRegistry() { - return getJpaMetamodel().getServiceRegistry(); - } + /** + * @apiNote Avoid calling this method, since {@link Class} + * objects are not available to the query validator + * in Hibernate Processor at compilation time. + */ + Class classForName(String className); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlAstCreationContext.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlAstCreationContext.java index 9b66286714..0f2acf53c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlAstCreationContext.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/SqlAstCreationContext.java @@ -9,7 +9,6 @@ package org.hibernate.sql.ast.spi; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.spi.MappingMetamodelImplementor; import org.hibernate.query.BindingContext; -import org.hibernate.service.ServiceRegistry; /** * The "context" in which creation of SQL AST occurs. Provides @@ -28,11 +27,6 @@ public interface SqlAstCreationContext extends BindingContext { */ MappingMetamodelImplementor getMappingMetamodel(); - /** - * Access to Services - */ - ServiceRegistry getServiceRegistry(); - /** * When creating {@link org.hibernate.sql.results.graph.Fetch} references, * defines a limit to how deep we should join for fetches. diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/BaseSqmUnitTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/BaseSqmUnitTest.java index 2055c65422..195d46f889 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/BaseSqmUnitTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/BaseSqmUnitTest.java @@ -15,7 +15,6 @@ import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.spi.MappingMetamodelImplementor; import org.hibernate.query.sqm.tree.select.SqmSelectStatement; -import org.hibernate.service.ServiceRegistry; import org.hibernate.sql.ast.spi.SqlAstCreationContext; import org.hibernate.sql.exec.spi.Callback; @@ -92,11 +91,6 @@ public abstract class BaseSqmUnitTest return sessionFactory().getJpaMetamodel(); } - @Override - public ServiceRegistry getServiceRegistry() { - return sessionFactory().getServiceRegistry(); - } - @Override public Integer getMaximumFetchDepth() { return sessionFactory().getMaximumFetchDepth(); diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java index 76fb36d99c..ead587c394 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java @@ -24,6 +24,7 @@ import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.boot.spi.BootstrapContext; @@ -364,6 +365,12 @@ public abstract class MockSessionFactory return serviceRegistry; } + @Override + public Class classForName(String className) { + return serviceRegistry.requireService( ClassLoaderService.class ) + .classForName( className ); + } + @Override public JdbcServices getJdbcServices() { return MockJdbcServicesInitiator.jdbcServices;