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 e78b4f9532..7a0f424995 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 @@ -17,7 +17,6 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceUnitUtil; import javax.persistence.Query; import javax.persistence.SynchronizationType; -import javax.persistence.criteria.CriteriaBuilder; import org.hibernate.CustomEntityDirtinessStrategy; import org.hibernate.EntityNameResolver; @@ -43,6 +42,7 @@ import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.factory.IdentifierGeneratorFactory; import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.CollectionMetadata; +import org.hibernate.metamodel.RuntimeMetamodels; import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.spi.MetamodelImplementor; @@ -51,7 +51,6 @@ import org.hibernate.persister.entity.EntityPersister; import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.query.criteria.HibernateCriteriaBuilder; import org.hibernate.query.spi.QueryEngine; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.type.Type; @@ -140,6 +139,11 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor, return delegate.getStatistics(); } + @Override + public RuntimeMetamodels getRuntimeMetamodels() { + return delegate.getRuntimeMetamodels(); + } + @Override public void close() throws HibernateException { delegate.close(); 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 a50c2e53cd..9968244364 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 @@ -31,7 +31,8 @@ import org.hibernate.engine.profile.FetchProfile; import org.hibernate.exception.spi.SQLExceptionConverter; import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.id.IdentifierGenerator; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; +import org.hibernate.metamodel.RuntimeMetamodels; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; @@ -81,7 +82,7 @@ public interface SessionFactoryImplementor } @Override - default DomainMetamodel getDomainModel() { + default MappingMetamodel getDomainModel() { return getMetamodel(); } @@ -104,6 +105,8 @@ public interface SessionFactoryImplementor @Override StatisticsImplementor getStatistics(); + RuntimeMetamodels getRuntimeMetamodels(); + /** * Access to the ServiceRegistry for this SessionFactory. * 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 2884c4e0d7..32a55c3658 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -101,10 +101,11 @@ import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.CollectionMetadata; +import org.hibernate.metamodel.RuntimeMetamodels; +import org.hibernate.metamodel.internal.RuntimeMetamodelsImpl; import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.JpaMetamodel; -import org.hibernate.metamodel.model.domain.internal.DomainMetamodelImpl; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Loadable; @@ -179,7 +180,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { // todo : org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor too? - private final transient DomainMetamodel metamodel; + private final transient RuntimeMetamodels runtimeMetamodels; private final PersistenceUnitUtil jpaPersistenceUnitUtil; private final transient CacheImplementor cacheAccess; private final transient QueryEngine queryEngine; @@ -298,8 +299,9 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { primeSecondLevelCacheRegions( bootMetamodel ); - this.metamodel = typeConfiguration.scope( this ); - ( (DomainMetamodelImpl) metamodel ).finishInitialization( + final RuntimeMetamodelsImpl runtimeMetamodels = new RuntimeMetamodelsImpl(); + this.runtimeMetamodels = runtimeMetamodels; + runtimeMetamodels.finishInitialization( bootMetamodel, bootstrapContext, this @@ -334,10 +336,10 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { final FetchProfile fetchProfile = new FetchProfile( mappingProfile.getName() ); for ( org.hibernate.mapping.FetchProfile.Fetch mappingFetch : mappingProfile.getFetches() ) { // resolve the persister owning the fetch - final String entityName = metamodel.getImportedName( mappingFetch.getEntity() ); + final String entityName = this.runtimeMetamodels.getImportedName( mappingFetch.getEntity() ); final EntityPersister owner = entityName == null ? null - : metamodel.getEntityDescriptor( entityName ); + : this.runtimeMetamodels.getMappingMetamodel().getEntityDescriptor( entityName ); if ( owner == null ) { throw new HibernateException( "Unable to resolve entity reference [" + mappingFetch.getEntity() @@ -715,7 +717,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { @Override public MetamodelImplementor getMetamodel() { validateNotClosed(); - return (MetamodelImplementor) metamodel; + return (MetamodelImplementor) runtimeMetamodels.getMappingMetamodel(); } @Override @@ -826,8 +828,8 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { cacheAccess.close(); } - if ( metamodel != null ) { - ( (DomainMetamodelImpl) metamodel ).close(); + if ( runtimeMetamodels != null ) { + ( (MappingMetamodelImpl) runtimeMetamodels.getMappingMetamodel() ).close(); } if ( queryEngine != null ) { @@ -1021,9 +1023,15 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { } } + @Override + public RuntimeMetamodels getRuntimeMetamodels() { + return runtimeMetamodels; + + } + @Override public JpaMetamodel getJpaMetamodel() { - return getMetamodel().getJpaMetamodel(); + return runtimeMetamodels.getJpaMetamodel(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/DomainMetamodel.java b/hibernate-core/src/main/java/org/hibernate/metamodel/MappingMetamodel.java similarity index 81% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/DomainMetamodel.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/MappingMetamodel.java index 9cd2191535..070d0431b8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/DomainMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/MappingMetamodel.java @@ -4,7 +4,7 @@ * 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.metamodel.spi; +package org.hibernate.metamodel; import java.util.List; import java.util.function.Consumer; @@ -14,45 +14,29 @@ import org.hibernate.graph.RootGraph; import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.metamodel.model.domain.JpaMetamodel; -import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.query.sqm.SqmExpressable; -import org.hibernate.type.BasicType; import org.hibernate.type.spi.TypeConfiguration; /** - * Access to information about Hibernate's runtime type system + * Access to information about Hibernate's runtime relational mapping model * * @author Steve Ebersole */ @Incubating -public interface DomainMetamodel { - /** - * Access to the JPA metamodel sub-set of the overall run-time metamodel - * - * @apiNote The distinction is mainly used in building SQM trees, which rely - * on the JPA type subset - */ - JpaMetamodel getJpaMetamodel(); - +public interface MappingMetamodel { /** * The TypeConfiguration this metamodel is associated with */ - default TypeConfiguration getTypeConfiguration() { - return getJpaMetamodel().getTypeConfiguration(); - } + TypeConfiguration getTypeConfiguration(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // Mapping model + // SQM model -> Mapping model /** * todo (6.0) : POC!!! Intended for use in SQM -> SQL translation - * - * @param sqmExpressable - * @return */ MappingModelExpressable resolveMappingExpressable(SqmExpressable sqmExpressable); @@ -60,28 +44,7 @@ public interface DomainMetamodel { * Given a Java type, determine the corresponding AllowableParameterType to * use implicitly */ - default AllowableParameterType resolveQueryParameterType(Class javaType) { - final BasicType basicType = getTypeConfiguration().getBasicTypeForJavaType( javaType ); - if ( basicType != null ) { - //noinspection unchecked - return basicType; - } - - final ManagedDomainType managedType = getJpaMetamodel().findManagedType( javaType ); - if ( managedType instanceof AllowableParameterType ) { - //noinspection unchecked - return (AllowableParameterType) managedType; - } - - return null; - } - - /** - * Given an (assumed) entity instance, determine its descriptor - * - * @see org.hibernate.EntityNameResolver - */ - EntityPersister determineEntityPersister(Object entity); + AllowableParameterType resolveQueryParameterType(Class javaType); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/RuntimeMetamodels.java b/hibernate-core/src/main/java/org/hibernate/metamodel/RuntimeMetamodels.java new file mode 100644 index 0000000000..dc16a16ae6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/RuntimeMetamodels.java @@ -0,0 +1,57 @@ +/* + * 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.metamodel; + +import org.hibernate.Incubating; +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; +import org.hibernate.metamodel.mapping.EntityMappingType; +import org.hibernate.metamodel.mapping.PluralAttributeMapping; +import org.hibernate.metamodel.model.domain.JpaMetamodel; + +/** + * Access to Hibernate's runtime metamodels which includes its domain-model (JPA impl) and its + * relational-mapping model + * + * @author Steve Ebersole + */ +@Incubating +public interface RuntimeMetamodels { + /** + * Access to the JPA / domain metamodel + */ + JpaMetamodel getJpaMetamodel(); + + /** + * Access to the relational-mapping model + */ + MappingMetamodel getMappingMetamodel(); + + + // some convenience methods... + + default EntityMappingType getEntityMappingType(String entityName) { + return getMappingMetamodel().getEntityDescriptor( entityName ); + } + + default EntityMappingType getEntityMappingType(Class entityType) { + return getMappingMetamodel().getEntityDescriptor( entityType ); + } + + default PluralAttributeMapping getPluralAttributeMapping(String role) { + return getMappingMetamodel().findCollectionDescriptor( role ).getAttributeMapping(); + } + + default EmbeddableValuedModelPart getEmbedded(String role) { + // todo (6.0) : I think we might need a form of mapping-model look-up for embeddables, something like: + throw new NotYetImplementedFor6Exception( getClass() ); + } + + default String getImportedName(String name) { + return getMappingMetamodel().getImportedName( name ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/ValueClassification.java b/hibernate-core/src/main/java/org/hibernate/metamodel/ValueClassification.java index f841d3daea..fb24eabde8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/ValueClassification.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/ValueClassification.java @@ -7,11 +7,28 @@ package org.hibernate.metamodel; /** + * At the end of the day, any "value mapping" (id, version, attribute, collection element, etc) can be one + * of a few classifications. This defines an enumeration of those classifications + * * @author Steve Ebersole */ public enum ValueClassification { + /** + * The mapped value is a basic value (String, Date, etc). + */ BASIC, + /** + * ANY is a Hibernate specific concept. It is essentially a "reverse discrimination". Here, the association itself + * defines a discriminator to the associated entity - sort of the reverse of discriminator-inheritance. Here the + * various associated types can be unrelated in terms of mapped inheritance. + */ ANY, + /** + * An {@link javax.persistence.Embeddable} value + */ EMBEDDABLE, + /** + * Reference to an entity + */ ENTITY } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index 6dd55238f0..b12e681120 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -43,16 +43,16 @@ import org.hibernate.metamodel.model.domain.PersistentAttribute; import org.hibernate.metamodel.model.domain.SingularPersistentAttribute; import org.hibernate.metamodel.model.domain.internal.AttributeContainer; import org.hibernate.metamodel.model.domain.internal.BasicTypeImpl; -import org.hibernate.metamodel.model.domain.internal.DomainMetamodelImpl; +import org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl; import org.hibernate.metamodel.model.domain.internal.EntityTypeImpl; import org.hibernate.metamodel.model.domain.internal.MappedSuperclassTypeImpl; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.type.descriptor.java.spi.JavaTypeDescriptorRegistry; import org.hibernate.type.spi.TypeConfiguration; /** - * Defines a context for storing information during the building of the {@link DomainMetamodelImpl}. + * Defines a context for storing information during the building of the {@link MappingMetamodelImpl}. *

* This contextual information includes data needing to be processed in a second pass as well as * cross-references into the built metamodel classes. @@ -94,7 +94,7 @@ public class MetadataContext { * Stack of PersistentClass being process. Last in the list is the highest in the stack. */ private List stackOfPersistentClassesBeingProcessed = new ArrayList<>(); - private DomainMetamodel metamodel; + private MappingMetamodel metamodel; public MetadataContext( JpaMetamodel jpaMetamodel, @@ -125,7 +125,7 @@ public class MetadataContext { return typeConfiguration.getJavaTypeDescriptorRegistry(); } - DomainMetamodel getMetamodel() { + MappingMetamodel getMetamodel() { return metamodel; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeMetamodelsImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeMetamodelsImpl.java new file mode 100644 index 0000000000..926cd7c7fd --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeMetamodelsImpl.java @@ -0,0 +1,55 @@ +/* + * 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.metamodel.internal; + +import org.hibernate.boot.spi.BootstrapContext; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.internal.SessionFactoryImpl; +import org.hibernate.metamodel.MappingMetamodel; +import org.hibernate.metamodel.RuntimeMetamodels; +import org.hibernate.metamodel.model.domain.JpaMetamodel; +import org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl; + +/** + * @author Steve Ebersole + */ +public class RuntimeMetamodelsImpl implements RuntimeMetamodels { + private JpaMetamodel jpaMetamodel; + private MappingMetamodel mappingMetamodel; + + public RuntimeMetamodelsImpl() { + } + + @Override + public JpaMetamodel getJpaMetamodel() { + return jpaMetamodel; + } + + @Override + public MappingMetamodel getMappingMetamodel() { + return mappingMetamodel; + } + + /** + * Chicken-and-egg because things try to use the SessionFactory (specifically the MappingMetamodel) + * before it is ready. So we do this fugly code... + */ + public void finishInitialization( + MetadataImplementor bootMetamodel, + BootstrapContext bootstrapContext, + SessionFactoryImpl sessionFactory) { + final MappingMetamodelImpl mappingMetamodel = bootstrapContext.getTypeConfiguration().scope( sessionFactory ); + this.mappingMetamodel = mappingMetamodel; + mappingMetamodel.finishInitialization( + bootMetamodel, + bootstrapContext, + sessionFactory + ); + + this.jpaMetamodel = mappingMetamodel.getJpaMetamodel(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardPojoEntityRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardPojoEntityRepresentationStrategy.java index f9e1331160..3ad94b53a5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardPojoEntityRepresentationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/StandardPojoEntityRepresentationStrategy.java @@ -77,7 +77,7 @@ public class StandardPojoEntityRepresentationStrategy implements EntityRepresent PersistentClass bootDescriptor, RuntimeModelCreationContext creationContext) { final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); - final JavaTypeDescriptorRegistry jtdRegistry = sessionFactory.getTypeConfiguration() + final JavaTypeDescriptorRegistry jtdRegistry = creationContext.getTypeConfiguration() .getJavaTypeDescriptorRegistry(); final Class mappedJavaType = bootDescriptor.getMappedClass(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableValuedModelPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableValuedModelPart.java index 0d7d372a4e..a5e1ecb71a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableValuedModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableValuedModelPart.java @@ -18,6 +18,12 @@ import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.sql.results.graph.FetchableContainer; /** + * An embedded (embeddable-valued) model part. + * + * @see javax.persistence.Embedded + * @see javax.persistence.EmbeddedId + * @see javax.persistence.Embeddable + * * @author Steve Ebersole */ public interface EmbeddableValuedModelPart extends ModelPart, Fetchable, FetchableContainer, TableGroupJoinProducer { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java index d126d5db8d..d8c2728d1b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java @@ -63,7 +63,7 @@ import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.mapping.StateArrayContributorMetadata; import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess; import org.hibernate.metamodel.model.convert.spi.BasicValueConverter; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.SQLLoadableCollection; @@ -690,7 +690,7 @@ public class MappingModelCreationHelper { final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext(); final SessionFactoryImplementor sessionFactory = creationContext.getSessionFactory(); final Dialect dialect = sessionFactory.getJdbcServices().getJdbcEnvironment().getDialect(); - final DomainMetamodel domainModel = creationContext.getDomainModel(); + final MappingMetamodel domainModel = creationContext.getDomainModel(); final CollectionPersister collectionDescriptor = domainModel.findCollectionDescriptor( bootValueMapping.getRole() ); assert collectionDescriptor != null; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/package-info.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/package-info.java index 3693f3c6b8..4ae3f6fee0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/package-info.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/package-info.java @@ -6,9 +6,14 @@ */ /** - * Hibernate's run-time mapping model. + * Hibernate's run-time mapping model. This model defines the mapping of the application's domain model + * to database objects (tables, columns, etc). * - * @implNote At the moment, this mapping model is built on top of the - * {@link org.hibernate.persister} package. + * @implNote At the moment, this mapping model is built on top of the {@link org.hibernate.persister} package. + * + * @implSpec This entire package is considered an SPI and incubating at the moment */ +@Incubating package org.hibernate.metamodel.mapping; + +import org.hibernate.Incubating; \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/JpaMetamodel.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/JpaMetamodel.java index 9910eae93e..44e81694c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/JpaMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/JpaMetamodel.java @@ -15,7 +15,7 @@ import javax.persistence.metamodel.ManagedType; import org.hibernate.Incubating; import org.hibernate.graph.spi.RootGraphImplementor; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.service.ServiceRegistry; import org.hibernate.type.spi.TypeConfiguration; @@ -23,7 +23,7 @@ import org.hibernate.type.spi.TypeConfiguration; * Hibernate extension to the JPA {@link javax.persistence.metamodel.Metamodel} contract * * @author Steve Ebersole - * @see DomainMetamodel + * @see MappingMetamodel */ @Incubating public interface JpaMetamodel extends javax.persistence.metamodel.Metamodel { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java similarity index 93% rename from hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java index 5224a0c15b..67b0ae2f51 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java @@ -42,15 +42,16 @@ import org.hibernate.internal.HEMLogging; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting; import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess; +import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.NavigableRole; -import org.hibernate.metamodel.spi.DomainMetamodel; import org.hibernate.metamodel.spi.EntityRepresentationStrategy; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; @@ -70,14 +71,17 @@ import static org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetti * * Really more of the mapping model then the domain model, though it does have reference to the `JpaMetamodel` * + * NOTE : we suppress deprecation warnings because at the moment we still implement a deprecated API so + * have to reference deprecated things * * @author Steve Ebersole * @author Emmanuel Bernard * @author Andrea Boriero */ -public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplementor, Serializable { +@SuppressWarnings("deprecation") +public class MappingMetamodelImpl implements MappingMetamodel, MetamodelImplementor, Serializable { // todo : Integrate EntityManagerLogger into CoreMessageLogger - private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( DomainMetamodelImpl.class ); + private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( MappingMetamodelImpl.class ); private static final String INVALID_IMPORT = ""; private static final String[] EMPTY_IMPLEMENTORS = new String[0]; @@ -123,7 +127,7 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento // // To account for this, we track both paradigms here... - /** + /* * There can be multiple instances of an Embeddable type, each one being relative to its parent entity. */ @@ -142,12 +146,16 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento private final Map implementorsCache = new ConcurrentHashMap<>(); - public DomainMetamodelImpl(SessionFactoryImplementor sessionFactory, TypeConfiguration typeConfiguration) { + public MappingMetamodelImpl(SessionFactoryImplementor sessionFactory, TypeConfiguration typeConfiguration) { this.sessionFactory = sessionFactory; this.typeConfiguration = typeConfiguration; this.jpaMetamodel = new JpaMetamodelImpl( typeConfiguration ); } + public JpaMetamodel getJpaMetamodel() { + return jpaMetamodel; + } + public void finishInitialization( MetadataImplementor bootModel, BootstrapContext bootstrapContext, @@ -170,8 +178,8 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento } @Override - public DomainMetamodel getDomainModel() { - return DomainMetamodelImpl.this; + public MappingMetamodel getDomainModel() { + return MappingMetamodelImpl.this; } }; @@ -294,6 +302,7 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento if ( indexType != null && indexType.isEntityType() && !indexType.isAnyType() ) { String entityName = ( (org.hibernate.type.EntityType) indexType ).getAssociatedEntityName(); Set roles = collectionRolesByEntityParticipant.get( entityName ); + //noinspection Java8MapApi if ( roles == null ) { roles = new HashSet<>(); collectionRolesByEntityParticipant.put( entityName, roles ); @@ -304,6 +313,7 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento if ( elementType.isEntityType() && !elementType.isAnyType() ) { String entityName = ( (org.hibernate.type.EntityType) elementType ).getAssociatedEntityName(); Set roles = collectionRolesByEntityParticipant.get( entityName ); + //noinspection Java8MapApi if ( roles == null ) { roles = new HashSet<>(); collectionRolesByEntityParticipant.put( entityName, roles ); @@ -339,16 +349,6 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento return typeConfiguration; } - @Override - public JpaMetamodel getJpaMetamodel() { - return this.jpaMetamodel; - } - - @Override - public EntityPersister determineEntityPersister(Object entity) { - return findEntityDescriptor( entity.getClass() ); - } - @Override public void visitEntityDescriptors(Consumer action) { entityPersisterMap.values().forEach( action ); @@ -423,42 +423,38 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento } @Override - @SuppressWarnings({ "unchecked" }) public EntityDomainType entity(Class cls) { - return getJpaMetamodel().entity( cls ); + return jpaMetamodel.entity( cls ); } @Override - @SuppressWarnings({ "unchecked" }) public ManagedDomainType managedType(Class cls) { - return getJpaMetamodel().managedType( cls ); + return jpaMetamodel.managedType( cls ); } @Override - @SuppressWarnings({ "unchecked" }) public EmbeddableDomainType embeddable(Class cls) { - return getJpaMetamodel().embeddable( cls ); + return jpaMetamodel.embeddable( cls ); } @Override public Set> getManagedTypes() { - return getJpaMetamodel().getManagedTypes(); + return jpaMetamodel.getManagedTypes(); } @Override public Set> getEntities() { - return getJpaMetamodel().getEntities(); + return jpaMetamodel.getEntities(); } @Override public Set> getEmbeddables() { - return getJpaMetamodel().getEmbeddables(); + return jpaMetamodel.getEmbeddables(); } @Override - @SuppressWarnings("unchecked") public EntityDomainType entity(String entityName) { - return getJpaMetamodel().entity( entityName ); + return jpaMetamodel.entity( entityName ); } @Override @@ -596,15 +592,13 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento } @Override - @SuppressWarnings("unchecked") public RootGraphImplementor findEntityGraphByName(String name) { - return getJpaMetamodel().findEntityGraphByName( name ); + return jpaMetamodel.findEntityGraphByName( name ); } @Override - @SuppressWarnings("unchecked") public List> findEntityGraphsByJavaType(Class entityClass) { - return getJpaMetamodel().findEntityGraphsByJavaType( entityClass ); + return jpaMetamodel.findEntityGraphsByJavaType( entityClass ); } @Override @@ -709,4 +703,21 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento throw new UnsupportedOperationException( "Cannot determine proper mapping model expressable for " + sqmExpressable ); } + + @Override + public AllowableParameterType resolveQueryParameterType(Class javaType) { + final BasicType basicType = getTypeConfiguration().getBasicTypeForJavaType( javaType ); + if ( basicType != null ) { + //noinspection unchecked + return basicType; + } + + final ManagedDomainType managedType = jpaMetamodel.findManagedType( javaType ); + if ( managedType instanceof AllowableParameterType ) { + //noinspection unchecked + return (AllowableParameterType) managedType; + } + + return null; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java index 6da72623ee..b8a1afd351 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java @@ -17,6 +17,7 @@ import org.hibernate.MappingException; import org.hibernate.Metamodel; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.graph.spi.RootGraphImplementor; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.ManagedDomainType; @@ -29,10 +30,10 @@ import org.hibernate.type.spi.TypeConfiguration; * * @author Steve Ebersole * - * @deprecated (since 6.0) - Prefer {@link org.hibernate.metamodel.spi.DomainMetamodel} + * @deprecated (since 6.0) - Prefer {@link MappingMetamodel} */ @Deprecated -public interface MetamodelImplementor extends DomainMetamodel, Metamodel { +public interface MetamodelImplementor extends MappingMetamodel, Metamodel { /** * Access to the TypeConfiguration in effect for this SessionFactory/Metamodel * diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeModelCreationContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeModelCreationContext.java index cea6969b3e..14e9c4af00 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeModelCreationContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeModelCreationContext.java @@ -9,6 +9,7 @@ package org.hibernate.metamodel.spi; import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.type.descriptor.java.spi.JavaTypeDescriptorRegistry; @@ -24,7 +25,7 @@ public interface RuntimeModelCreationContext extends PersisterCreationContext { MetadataImplementor getBootModel(); - DomainMetamodel getDomainModel(); + MappingMetamodel getDomainModel(); default TypeConfiguration getTypeConfiguration() { return getBootstrapContext().getTypeConfiguration(); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index 995ae6ca26..2bda9184c2 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -77,6 +77,7 @@ import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.mapping.internal.PluralAttributeMappingImpl; import org.hibernate.metamodel.model.convert.spi.BasicValueConverter; import org.hibernate.metamodel.model.domain.NavigableRole; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.PropertyMapping; import org.hibernate.persister.entity.Queryable; @@ -259,7 +260,11 @@ public abstract class AbstractCollectionPersister public AbstractCollectionPersister( Collection collectionBootDescriptor, CollectionDataAccess cacheAccessStrategy, - PersisterCreationContext creationContext) throws MappingException, CacheException { + PersisterCreationContext pcc) throws MappingException, CacheException { + assert pcc instanceof RuntimeModelCreationContext; + + final RuntimeModelCreationContext creationContext = (RuntimeModelCreationContext) pcc; + final Value elementBootDescriptor = collectionBootDescriptor.getElement(); final Value indexBootDescriptor = collectionBootDescriptor instanceof IndexedCollection ? ( (IndexedCollection) collectionBootDescriptor ).getIndex() @@ -284,7 +289,7 @@ public abstract class AbstractCollectionPersister collectionType = collectionBootDescriptor.getCollectionType(); navigableRole = new NavigableRole( collectionBootDescriptor.getRole() ); entityName = collectionBootDescriptor.getOwnerEntityName(); - ownerPersister = factory.getEntityPersister( entityName ); + ownerPersister = creationContext.getDomainModel().getEntityDescriptor( entityName ); queryLoaderName = collectionBootDescriptor.getLoaderName(); isMutable = collectionBootDescriptor.isMutable(); mappedByProperty = collectionBootDescriptor.getMappedByProperty(); @@ -346,7 +351,7 @@ public abstract class AbstractCollectionPersister if ( elementType.isEntityType() ) { String entityName = ( (EntityType) elementType ).getAssociatedEntityName(); - elementPersister = factory.getEntityPersister( entityName ); + elementPersister = creationContext.getDomainModel().getEntityDescriptor( entityName ); // NativeSQL: collect element column and auto-aliases } @@ -2416,6 +2421,11 @@ public abstract class AbstractCollectionPersister this.attributeMapping = attributeMapping; } + @Override + public PluralAttributeMapping getAttributeMapping() { + return attributeMapping; + } + @Override public boolean isAffectedByEnabledFilters(LoadQueryInfluencers influencers) { if ( influencers.hasEnabledFilters() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPersister.java index 1621667b89..15636c1211 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPersister.java @@ -25,6 +25,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.id.IdentifierGenerator; import org.hibernate.metadata.CollectionMetadata; import org.hibernate.metamodel.CollectionClassification; +import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.model.convert.spi.BasicValueConverter; import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.persister.entity.EntityPersister; @@ -296,6 +297,10 @@ public interface CollectionPersister extends CollectionDefinition { boolean isAffectedByEnabledFilters(SharedSessionContractImplementor session); + default PluralAttributeMapping getAttributeMapping() { + throw new UnsupportedOperationException( "CollectionPersister used for [" + getRole() + "] does not support SQL AST" ); + } + default boolean isAffectedByEnabledFilters(LoadQueryInfluencers influencers) { throw new UnsupportedOperationException( "CollectionPersister used for [" + getRole() + "] does not support SQL AST" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java index d21df6f078..c0ac37d5bf 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java @@ -1084,7 +1084,7 @@ public abstract class AbstractQuery implements QueryImplementor { } else { final ManagedDomainType managedDomainType = getSession().getFactory() - .getDomainModel() + .getRuntimeMetamodels() .getJpaMetamodel() .managedType( javaType ); if ( managedDomainType != null ) { @@ -1119,7 +1119,7 @@ public abstract class AbstractQuery implements QueryImplementor { } else { final ManagedDomainType managedDomainType = getSession().getFactory() - .getDomainModel() + .getRuntimeMetamodels() .getJpaMetamodel() .managedType( javaType ); if ( managedDomainType != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java index 348f3061b1..57bce42e3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java @@ -113,10 +113,13 @@ import static org.hibernate.query.internal.QueryHelper.highestPrecedenceType; * @author Steve Ebersole */ public class SqmCriteriaNodeBuilder implements NodeBuilder { + /** + * Simplified creation from a SessionFactory + */ public static SqmCriteriaNodeBuilder create(SessionFactoryImplementor sf) { return new SqmCriteriaNodeBuilder( sf.getQueryEngine(), - sf.getMetamodel().getJpaMetamodel(), + sf.getRuntimeMetamodels().getJpaMetamodel(), sf.getServiceRegistry() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmMappingModelHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmMappingModelHelper.java index 3bb7f7e081..b0192bad80 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmMappingModelHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmMappingModelHelper.java @@ -24,7 +24,7 @@ import org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource; import org.hibernate.metamodel.model.domain.internal.DomainModelHelper; import org.hibernate.metamodel.model.domain.internal.EmbeddedSqmPathSource; import org.hibernate.metamodel.model.domain.internal.EntitySqmPathSource; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.query.NavigablePath; import org.hibernate.query.sqm.SqmExpressable; @@ -103,7 +103,7 @@ public class SqmMappingModelHelper { public static MappingModelExpressable resolveMappingModelExpressable( SqmTypedNode sqmNode, - DomainMetamodel domainModel, + MappingMetamodel domainModel, Function tableGroupLocator) { if ( sqmNode instanceof SqmPath ) { return resolveSqmPath( (SqmPath) sqmNode, domainModel, tableGroupLocator ); @@ -119,7 +119,7 @@ public class SqmMappingModelHelper { private static ModelPart resolveSqmPath( SqmPath sqmPath, - DomainMetamodel domainModel, + MappingMetamodel domainModel, Function tableGroupLocator) { if ( sqmPath instanceof SqmTreatedPath ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java index 8514e0af77..29d6aeeed0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java @@ -22,7 +22,7 @@ import org.hibernate.metamodel.mapping.Bindable; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.metamodel.model.domain.AllowableParameterType; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.query.IllegalQueryOperationException; import org.hibernate.query.NavigablePath; import org.hibernate.query.spi.QueryParameterBinding; @@ -156,7 +156,7 @@ public class SqmUtil { QueryParameterBindings domainParamBindings, DomainParameterXref domainParameterXref, Map, Map>> jdbcParamXref, - DomainMetamodel domainModel, + MappingMetamodel domainModel, Function tableGroupLocator, SharedSessionContractImplementor session) { final JdbcParameterBindings jdbcParameterBindings = new JdbcParameterBindingsImpl( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/TableBasedUpdateHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/TableBasedUpdateHandler.java index 24fb247dfa..2422da890b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/TableBasedUpdateHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/idtable/TableBasedUpdateHandler.java @@ -20,7 +20,7 @@ import org.hibernate.boot.TempTableDdlTransactionHandling; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.util.collections.Stack; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Joinable; import org.hibernate.query.sqm.internal.DomainParameterXref; @@ -106,7 +106,7 @@ public class TableBasedUpdateHandler private ExecutionDelegate resolveDelegate(ExecutionContext executionContext) { final SessionFactoryImplementor sessionFactory = getSessionFactory(); - final DomainMetamodel domainModel = sessionFactory.getDomainModel(); + final MappingMetamodel domainModel = sessionFactory.getDomainModel(); final EntityPersister entityDescriptor = domainModel.getEntityDescriptor( getSqmDeleteOrUpdateStatement().getTarget().getEntityName() ); final String rootEntityName = entityDescriptor.getRootEntityName(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/StandardSqmUpdateTranslator.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/StandardSqmUpdateTranslator.java index b070f617fc..c9b71c5ddc 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/StandardSqmUpdateTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/StandardSqmUpdateTranslator.java @@ -13,7 +13,7 @@ import java.util.function.Function; import org.hibernate.HibernateException; import org.hibernate.LockMode; import org.hibernate.NotYetImplementedFor6Exception; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.query.NavigablePath; import org.hibernate.query.spi.QueryOptions; @@ -246,7 +246,7 @@ public class StandardSqmUpdateTranslator getJdbcParamsBySqmParam().put( sqmParameter, jdbcParametersForSqm ); } else { - final DomainMetamodel domainModel = getCreationContext().getDomainModel(); + final MappingMetamodel domainModel = getCreationContext().getDomainModel(); final TypeConfiguration typeConfiguration = domainModel.getTypeConfiguration(); final Expression valueExpression = (Expression) sqmAssignment.getValue().accept( this ); 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 52f4e44d25..443aa4ff8e 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 @@ -7,7 +7,7 @@ package org.hibernate.sql.ast.spi; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.service.ServiceRegistry; /** @@ -19,7 +19,7 @@ import org.hibernate.service.ServiceRegistry; public interface SqlAstCreationContext { SessionFactoryImplementor getSessionFactory(); - DomainMetamodel getDomainModel(); + MappingMetamodel getDomainModel(); ServiceRegistry getServiceRegistry(); diff --git a/hibernate-core/src/main/java/org/hibernate/type/spi/TypeConfiguration.java b/hibernate-core/src/main/java/org/hibernate/type/spi/TypeConfiguration.java index 9ced6702d2..44660af58a 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/spi/TypeConfiguration.java +++ b/hibernate-core/src/main/java/org/hibernate/type/spi/TypeConfiguration.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; @@ -25,13 +26,17 @@ import org.hibernate.SessionFactory; import org.hibernate.SessionFactoryObserver; import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService; import org.hibernate.boot.spi.BasicTypeRegistration; +import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.id.uuid.LocalObjectUuidHelper; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.SessionFactoryRegistry; -import org.hibernate.metamodel.model.domain.internal.DomainMetamodelImpl; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.RuntimeMetamodels; +import org.hibernate.metamodel.internal.RuntimeMetamodelsImpl; +import org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.query.BinaryArithmeticOperator; import org.hibernate.query.internal.QueryHelper; import org.hibernate.query.sqm.SqmExpressable; @@ -142,7 +147,7 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable { scope.setMetadataBuildingContext( metadataBuildingContext ); } - public DomainMetamodel scope(SessionFactoryImplementor sessionFactory) { + public MappingMetamodelImpl scope(SessionFactoryImplementor sessionFactory) { log.debugf( "Scoping TypeConfiguration [%s] to SessionFactoryImplementor [%s]", this, sessionFactory ); if ( scope.getMetadataBuildingContext() == null ) { @@ -151,7 +156,8 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable { scope.setSessionFactory( sessionFactory ); sessionFactory.addObserver( this ); - return new DomainMetamodelImpl( sessionFactory, this ); + + return new MappingMetamodelImpl( sessionFactory, this ); } /** diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java index f896a504b7..a7f17e05e0 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/QueryBuilderTest.java @@ -35,7 +35,7 @@ import org.hibernate.jpa.test.metamodel.Phone; import org.hibernate.jpa.test.metamodel.Product; import org.hibernate.jpa.test.metamodel.ShelfLife; import org.hibernate.jpa.test.metamodel.Spouse; -import org.hibernate.metamodel.model.domain.internal.DomainMetamodelImpl; +import org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl; import org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate; import org.hibernate.testing.FailureExpected; @@ -77,7 +77,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - DomainMetamodelImpl mm = (DomainMetamodelImpl) em.getMetamodel(); + MappingMetamodelImpl mm = (MappingMetamodelImpl) em.getMetamodel(); CriteriaQuery cquery = cb.createQuery( Integer.class ); Root product = cquery.from( Product.class ); @@ -135,7 +135,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - DomainMetamodelImpl mm = (DomainMetamodelImpl) em.getMetamodel(); + MappingMetamodelImpl mm = (MappingMetamodelImpl) em.getMetamodel(); EntityType Phone_ = mm.entity( Phone.class ); CriteriaQuery cquery = cb.createQuery( Phone.class ); @@ -157,7 +157,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - DomainMetamodelImpl mm = (DomainMetamodelImpl) em.getMetamodel(); + MappingMetamodelImpl mm = (MappingMetamodelImpl) em.getMetamodel(); EntityType Product_ = mm.entity( Product.class ); // toFloat @@ -189,7 +189,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - DomainMetamodelImpl mm = (DomainMetamodelImpl) em.getMetamodel(); + MappingMetamodelImpl mm = (MappingMetamodelImpl) em.getMetamodel(); CriteriaQuery cquery = cb.createQuery( Customer.class ); Root customer = cquery.from( Customer.class ); @@ -236,7 +236,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); - DomainMetamodelImpl mm = (DomainMetamodelImpl) em.getMetamodel(); + MappingMetamodelImpl mm = (MappingMetamodelImpl) em.getMetamodel(); CriteriaQuery dateQuery = cb.createQuery( java.sql.Date.class ); dateQuery.from( Customer.class ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/intg/sqm/HqlTranslationNoFactoryTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/intg/sqm/HqlTranslationNoFactoryTests.java index 2d316f701d..2afda87e21 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/intg/sqm/HqlTranslationNoFactoryTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/intg/sqm/HqlTranslationNoFactoryTests.java @@ -11,14 +11,12 @@ import java.util.Optional; import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.MetadataImplementor; -import org.hibernate.dialect.H2Dialect; -import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.query.hql.HqlTranslator; import org.hibernate.query.hql.internal.StandardHqlTranslator; @@ -35,7 +33,6 @@ import org.hibernate.testing.orm.junit.DomainModelScope; import org.hibernate.testing.orm.junit.FailureExpected; import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; /** @@ -89,7 +86,7 @@ public class HqlTranslationNoFactoryTests { } @Override - public DomainMetamodel getDomainModel() { + public MappingMetamodel getDomainModel() { throw new UnsupportedOperationException( "DomainMetamodel not available" ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/loading/MappedFetchTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/loading/MappedFetchTests.java index 0c3447693a..49c8bdcb83 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/loading/MappedFetchTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/loading/MappedFetchTests.java @@ -23,7 +23,7 @@ import org.hibernate.LockOptions; import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.loader.ast.internal.LoaderSelectBuilder; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableGroupJoin; @@ -64,7 +64,7 @@ public class MappedFetchTests { @Test public void baseline(SessionFactoryScope scope) { final SessionFactoryImplementor sessionFactory = scope.getSessionFactory(); - final DomainMetamodel domainModel = sessionFactory.getDomainModel(); + final MappingMetamodel domainModel = sessionFactory.getDomainModel(); final EntityPersister rootEntityDescriptor = domainModel.getEntityDescriptor( RootEntity.class ); final SelectStatement sqlAst = LoaderSelectBuilder.createSelect( diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/collections/PluralAttributeMappingTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/collections/PluralAttributeMappingTests.java index fb3912371b..c94ed741a0 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/collections/PluralAttributeMappingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/collections/PluralAttributeMappingTests.java @@ -9,7 +9,7 @@ package org.hibernate.orm.test.metamodel.mapping.collections; import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.PluralAttributeMapping; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.testing.orm.domain.StandardDomainModel; import org.hibernate.testing.orm.domain.gambit.EntityOfSets; @@ -36,7 +36,7 @@ public class PluralAttributeMappingTests { @Test public void testLists(SessionFactoryScope scope) { - final DomainMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor( EntityOfLists.class ); assertThat( containerEntityDescriptor.getNumberOfAttributeMappings(), is( 7 ) ); @@ -62,7 +62,7 @@ public class PluralAttributeMappingTests { @Test public void testSets(SessionFactoryScope scope) { - final DomainMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor( EntityOfSets.class ); assertThat( containerEntityDescriptor.getNumberOfAttributeMappings(), is( 9 ) ); @@ -94,7 +94,7 @@ public class PluralAttributeMappingTests { @Test public void testMaps(SessionFactoryScope scope) { - final DomainMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor( EntityOfMaps.class ); // 8 for now, until entity-valued map keys is supported diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java index 2c2781f51e..41d4276883 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/EntityManagerUnwrapTest.java @@ -16,7 +16,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; -import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.query.spi.QueryEngine; import org.hibernate.service.ServiceRegistry; @@ -53,7 +53,7 @@ public class EntityManagerUnwrapTest extends BaseEntityManagerFunctionalTestCase entityManagerFactory().unwrap( javax.persistence.metamodel.Metamodel.class ); entityManagerFactory().unwrap( Metamodel.class ); entityManagerFactory().unwrap( MetamodelImplementor.class ); - entityManagerFactory().unwrap( DomainMetamodel.class ); + entityManagerFactory().unwrap( MappingMetamodel.class ); entityManagerFactory().unwrap( QueryEngine.class ); }