diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/AbstractSelectLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/AbstractSelectLockingStrategy.java index 41d30585013a..232afd005c01 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/AbstractSelectLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/AbstractSelectLockingStrategy.java @@ -83,7 +83,7 @@ public void lock(Object id, Object version, Object object, int timeout, EventSou lockable.getVersionType().nullSafeSet( st, version, - lockable.getIdentifierType().getColumnSpan( factory ) + 1, + lockable.getIdentifierType().getColumnSpan( factory.getRuntimeMetamodels() ) + 1, session ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticReadUpdateLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticReadUpdateLockingStrategy.java index 430019387a71..2559ed5d0418 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticReadUpdateLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticReadUpdateLockingStrategy.java @@ -84,7 +84,7 @@ public void lock(Object id, Object version, Object object, int timeout, EventSou int offset = 2; lockable.getIdentifierType().nullSafeSet( st, id, offset, session ); - offset += lockable.getIdentifierType().getColumnSpan( factory ); + offset += lockable.getIdentifierType().getColumnSpan( factory.getRuntimeMetamodels() ); if ( lockable.isVersioned() ) { lockable.getVersionType().nullSafeSet( st, version, offset, session ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticWriteUpdateLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticWriteUpdateLockingStrategy.java index 349679ae1c2d..490df934fe84 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticWriteUpdateLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticWriteUpdateLockingStrategy.java @@ -83,7 +83,7 @@ public void lock(Object id, Object version, Object object, int timeout, EventSou int offset = 2; lockable.getIdentifierType().nullSafeSet( st, id, offset, session ); - offset += lockable.getIdentifierType().getColumnSpan( factory ); + offset += lockable.getIdentifierType().getColumnSpan( factory.getRuntimeMetamodels() ); if ( lockable.isVersioned() ) { lockable.getVersionType().nullSafeSet( st, version, offset, session ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/UpdateLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/UpdateLockingStrategy.java index cbe910916a3a..6147ff037fdf 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/UpdateLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/UpdateLockingStrategy.java @@ -90,7 +90,7 @@ public void lock( final Type lockableIdentifierType = lockable.getIdentifierType(); lockableIdentifierType.nullSafeSet( st, id, offset, session ); - offset += lockableIdentifierType.getColumnSpan( factory ); + offset += lockableIdentifierType.getColumnSpan( factory.getRuntimeMetamodels() ); if ( lockable.isVersioned() ) { lockableVersionType.nullSafeSet( st, version, offset, session ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/Mapping.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/Mapping.java index 59a2fc9a0ca6..96d2a42af1d0 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/Mapping.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/Mapping.java @@ -19,11 +19,10 @@ * @author Gavin King * * @deprecated Use {@link org.hibernate.type.spi.TypeConfiguration}, - * {@link org.hibernate.boot.Metadata}, or - * {@link org.hibernate.metamodel.RuntimeMetamodels} - * or {@link MappingContext} - * to access such information + * {@link org.hibernate.boot.Metadata}, + * {@link org.hibernate.metamodel.RuntimeMetamodels}, + * or {@link MappingContext} to access such information */ -@Deprecated(since = "6.0") +@Deprecated(since = "6.0", forRemoval = true) public interface Mapping extends MappingContext { } 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 57ab3e3b52e8..4b4b68f2b2be 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 @@ -23,7 +23,6 @@ import org.hibernate.CustomEntityDirtinessStrategy; import org.hibernate.HibernateException; -import org.hibernate.MappingException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.SessionFactoryObserver; @@ -55,7 +54,6 @@ import org.hibernate.sql.results.jdbc.spi.JdbcValuesMappingProducerProvider; import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.generator.Generator; -import org.hibernate.type.Type; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.spi.TypeConfiguration; @@ -298,21 +296,6 @@ public JavaType getTenantIdentifierJavaType() { return delegate.getTenantIdentifierJavaType(); } - @Override - public Type getIdentifierType(String className) throws MappingException { - return delegate.getIdentifierType( className ); - } - - @Override - public String getIdentifierPropertyName(String className) throws MappingException { - return delegate.getIdentifierPropertyName( className ); - } - - @Override - public Type getReferencedPropertyType(String className, String propertyName) throws MappingException { - return delegate.getReferencedPropertyType( className, propertyName ); - } - @Override public String getUuid() { return delegate.getUuid(); 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 0149e88982f8..397c67102cad 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 @@ -37,7 +37,6 @@ import org.hibernate.generator.Generator; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaType; -import org.hibernate.type.MappingContext; import org.hibernate.type.spi.TypeConfiguration; /** @@ -50,7 +49,7 @@ * @author Gavin King * @author Steve Ebersole */ -public interface SessionFactoryImplementor extends MappingContext, SessionFactory { +public interface SessionFactoryImplementor extends SessionFactory { /** * The UUID assigned to this {@code SessionFactory}. *

diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/UniqueKeySelectingDelegate.java b/hibernate-core/src/main/java/org/hibernate/id/insert/UniqueKeySelectingDelegate.java index 6b1dbe728238..89f7b8b090da 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/insert/UniqueKeySelectingDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/UniqueKeySelectingDelegate.java @@ -82,7 +82,7 @@ protected void bindParameters(Object entity, PreparedStatement ps, SharedSession int index = 1; for ( int i = 0; i < uniqueKeyPropertyNames.length; i++ ) { uniqueKeyTypes[i].nullSafeSet( ps, persister.getPropertyValue( entity, uniqueKeyPropertyNames[i] ), index, session ); - index += uniqueKeyTypes[i].getColumnSpan( session.getFactory() ); + index += uniqueKeyTypes[i].getColumnSpan( session.getFactory().getRuntimeMetamodels() ); } } } 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 05efbd0f1043..1199f21fe359 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -31,7 +31,6 @@ import org.hibernate.FlushMode; import org.hibernate.HibernateException; import org.hibernate.Interceptor; -import org.hibernate.MappingException; import org.hibernate.Session; import org.hibernate.SessionEventListener; import org.hibernate.SessionFactory; @@ -119,7 +118,6 @@ import org.hibernate.sql.ast.spi.ParameterMarkerStrategy; import org.hibernate.sql.results.jdbc.spi.JdbcValuesMappingProducerProvider; import org.hibernate.stat.spi.StatisticsImplementor; -import org.hibernate.type.Type; import org.hibernate.type.descriptor.WrapperOptions; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.spi.TypeConfiguration; @@ -781,21 +779,6 @@ public Reference getReference() { ); } - @Override - public Type getIdentifierType(String className) throws MappingException { - return runtimeMetamodels.getMappingMetamodel().getEntityDescriptor( className ).getIdentifierType(); - } - - @Override - public String getIdentifierPropertyName(String className) throws MappingException { - return runtimeMetamodels.getMappingMetamodel().getEntityDescriptor( className ).getIdentifierPropertyName(); - } - - @Override - public Type getReferencedPropertyType(String className, String propertyName) throws MappingException { - return runtimeMetamodels.getMappingMetamodel().getEntityDescriptor( className ).getPropertyType( propertyName ); - } - /** * Closes the session factory, releasing all held resources. * diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderInPredicate.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderInPredicate.java index e7dca28db76a..22ed710a856b 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderInPredicate.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityBatchLoaderInPredicate.java @@ -56,7 +56,9 @@ public EntityBatchLoaderInPredicate( super( entityDescriptor, loadQueryInfluencers ); this.loadQueryInfluencers = loadQueryInfluencers; this.domainBatchSize = domainBatchSize; - int idColumnCount = entityDescriptor.getEntityPersister().getIdentifierType().getColumnSpan( sessionFactory ); + int idColumnCount = + entityDescriptor.getEntityPersister().getIdentifierType() + .getColumnSpan( sessionFactory .getRuntimeMetamodels()); this.sqlBatchSize = sessionFactory.getJdbcServices() .getDialect() .getBatchLoadSizingStrategy() diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/StandardBatchLoaderFactory.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/StandardBatchLoaderFactory.java index 5b4bcf31ef4c..6d9c0fca184f 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/StandardBatchLoaderFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/StandardBatchLoaderFactory.java @@ -37,7 +37,7 @@ public EntityBatchLoader createEntityBatchLoader( final SessionFactoryImplementor factory = loadQueryInfluencers.getSessionFactory(); // NOTE : don't use the EntityIdentifierMapping here because it will not be known until later final Type identifierType = entityDescriptor.getEntityPersister().getIdentifierType(); - if ( identifierType.getColumnSpan( factory ) == 1 + if ( identifierType.getColumnSpan( factory.getRuntimeMetamodels() ) == 1 && supportsSqlArrayType( factory.getJdbcServices().getDialect() ) && identifierType instanceof BasicType ) { // we can use a single ARRAY parameter to send all the ids diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Collection.java b/hibernate-core/src/main/java/org/hibernate/mapping/Collection.java index deabdbd9587b..d8fc57e5d2fc 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Collection.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Collection.java @@ -381,7 +381,7 @@ public void setFetchMode(FetchMode fetchMode) { /** * @deprecated use {@link #validate(MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) public void validate(Mapping mapping) throws MappingException { validate( (MappingContext) mapping); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Column.java b/hibernate-core/src/main/java/org/hibernate/mapping/Column.java index 6d75ebfdf843..d76b1d0fbe78 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Column.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Column.java @@ -284,7 +284,7 @@ public boolean equals(Column column) { /** * @deprecated use {@link #getSqlTypeCode(MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) public int getSqlTypeCode(Mapping mapping) throws MappingException{ return getSqlTypeCode((MappingContext) mapping); } @@ -425,7 +425,7 @@ public String getSqlType(Metadata mapping) { /** * @deprecated use {@link #getSqlType(Metadata)} */ - @Deprecated(since = "6.2") + @Deprecated(since = "6.2", forRemoval = true) public String getSqlType(TypeConfiguration typeConfiguration, Dialect dialect, Mapping mapping) { return getSqlTypeName( typeConfiguration, dialect, mapping ); } @@ -463,7 +463,7 @@ public int getDecimalDigits() { /** * @deprecated use {@link #getColumnSize(Dialect, MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) public Size getColumnSize(Dialect dialect, Mapping mapping) { return getColumnSize(dialect, (MappingContext) mapping); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/IdentifierCollection.java b/hibernate-core/src/main/java/org/hibernate/mapping/IdentifierCollection.java index 500e646b963e..6400141ad318 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/IdentifierCollection.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/IdentifierCollection.java @@ -66,6 +66,7 @@ void createPrimaryKey() { // create an index on the key columns?? } + @Deprecated(forRemoval = true) public void validate(Mapping mapping) throws MappingException { validate( (MappingContext) mapping); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/IndexedCollection.java b/hibernate-core/src/main/java/org/hibernate/mapping/IndexedCollection.java index 1523c28f2ca8..d5762b53fcef 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/IndexedCollection.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/IndexedCollection.java @@ -96,7 +96,7 @@ void createPrimaryKey() { // } } - @Deprecated + @Deprecated(forRemoval = true) public void validate(Mapping mapping) throws MappingException { validate( (MappingContext) mapping); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java index 86af377bf737..5cb6139f6e5e 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java @@ -279,7 +279,7 @@ public void setMetaAttributes(Map metas) { /** * @deprecated use {@link #isValid(MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) public boolean isValid(Mapping mapping) throws MappingException { return isValid( (MappingContext) mapping); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Set.java b/hibernate-core/src/main/java/org/hibernate/mapping/Set.java index e2377d786343..ba55206f6e82 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Set.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Set.java @@ -48,6 +48,7 @@ public Set copy() { return new Set( this ); } + @Deprecated(forRemoval = true) public void validate(Mapping mapping) throws MappingException { validate( (MappingContext) mapping ); } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Value.java b/hibernate-core/src/main/java/org/hibernate/mapping/Value.java index 9ab6200ddd81..e4ffa5cb9deb 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Value.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Value.java @@ -75,7 +75,7 @@ default List getConstraintColumns() { /** * @deprecated use {@link #getSelectableType(MappingContext, int)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) default JdbcMapping getSelectableType(Mapping factory, int index) throws MappingException { return getSelectableType( (MappingContext) factory, index ); } @@ -146,7 +146,7 @@ private Type getIdType(EntityType entityType) { /** * @deprecated use {@link #isValid(MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) default boolean isValid(Mapping mapping) throws MappingException{ return isValid( (MappingContext) mapping ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/RuntimeMetamodels.java b/hibernate-core/src/main/java/org/hibernate/metamodel/RuntimeMetamodels.java index 1ae6fb057d44..1c0599a372a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/RuntimeMetamodels.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/RuntimeMetamodels.java @@ -5,11 +5,9 @@ package org.hibernate.metamodel; import org.hibernate.Incubating; -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; -import org.hibernate.metamodel.model.domain.NavigableRole; /** * Entry point providing access to the runtime metamodels: @@ -42,7 +40,7 @@ default EntityMappingType getEntityMappingType(String entityName) { return getMappingMetamodel().getEntityDescriptor( entityName ); } - default EntityMappingType getEntityMappingType(Class entityType) { + default EntityMappingType getEntityMappingType(Class entityType) { return getMappingMetamodel().getEntityDescriptor( entityType ); } @@ -50,13 +48,6 @@ default PluralAttributeMapping getPluralAttributeMapping(String role) { return getMappingMetamodel().findCollectionDescriptor( role ).getAttributeMapping(); } - /** - * @deprecated Use {@link #getEmbedded(NavigableRole)} instead - */ - @Deprecated - EmbeddableValuedModelPart getEmbedded(String role); - EmbeddableValuedModelPart getEmbedded(NavigableRole role); - default String getImportedName(String name) { return getMappingMetamodel().getImportedName( name ); } 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 index 22c92d4bd934..36109bb3f962 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeMetamodelsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeMetamodelsImpl.java @@ -4,16 +4,17 @@ */ package org.hibernate.metamodel.internal; -import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; -import org.hibernate.metamodel.model.domain.NavigableRole; +import org.hibernate.MappingException; import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor; import org.hibernate.metamodel.spi.MappingMetamodelImplementor; import org.hibernate.metamodel.spi.RuntimeMetamodelsImplementor; +import org.hibernate.type.Type; /** * @author Steve Ebersole */ public class RuntimeMetamodelsImpl implements RuntimeMetamodelsImplementor { + private JpaMetamodelImplementor jpaMetamodel; private MappingMetamodelImplementor mappingMetamodel; @@ -31,15 +32,21 @@ public MappingMetamodelImplementor getMappingMetamodel() { } @Override - public EmbeddableValuedModelPart getEmbedded(String role) { - throw new UnsupportedOperationException( "Locating EmbeddableValuedModelPart by (String) role is not supported" ); + public Type getIdentifierType(String className) throws MappingException { + return mappingMetamodel.getEntityDescriptor( className ).getIdentifierType(); } @Override - public EmbeddableValuedModelPart getEmbedded(NavigableRole role) { - return mappingMetamodel.getEmbeddableValuedModelPart( role ); + public String getIdentifierPropertyName(String className) throws MappingException { + return mappingMetamodel.getEntityDescriptor( className ).getIdentifierPropertyName(); } + @Override + public Type getReferencedPropertyType(String className, String propertyName) throws MappingException { + return mappingMetamodel.getEntityDescriptor( className ).getPropertyType( propertyName ); + } + + public void setMappingMetamodel(MappingMetamodelImplementor mappingMetamodel) { this.mappingMetamodel = mappingMetamodel; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java index c4ac4e7f1656..e396c1436a36 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java @@ -779,7 +779,8 @@ public static void addPrefixedPropertyNames( } } else if ( type instanceof EntityType entityType ) { - final Type identifierOrUniqueKeyType = entityType.getIdentifierOrUniqueKeyType( factory ); + final Type identifierOrUniqueKeyType = + entityType.getIdentifierOrUniqueKeyType( factory.getRuntimeMetamodels() ); final String propertyName; if ( entityType.isReferenceToPrimaryKey() ) { propertyName = entityType.getAssociatedEntityPersister( factory ).getIdentifierPropertyName(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java index bc275a51fe06..4d4a15362b8c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java @@ -54,7 +54,7 @@ static Expression applyCollation( final SqmToSqlAstConverter converter = creationState instanceof SqmToSqlAstConverter sqmToSqlAstConverter ? sqmToSqlAstConverter - : new FakeSqmToSqlAstConverter(creationState); + : new FakeSqmToSqlAstConverter( creationState ); sortExpression = queryEngine.getSqmFunctionRegistry() .findFunctionDescriptor( "collate" ) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeMetamodelsImplementor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeMetamodelsImplementor.java index eafd947be8a3..e1907ead37f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeMetamodelsImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeMetamodelsImplementor.java @@ -6,13 +6,14 @@ import org.hibernate.metamodel.RuntimeMetamodels; import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor; +import org.hibernate.type.MappingContext; /** - * SPI extending {@link RuntimeMetamodels}. + * SPI extending {@link RuntimeMetamodels} and mixing in {@link MappingContext}. * * @author Steve Ebersole */ -public interface RuntimeMetamodelsImplementor extends RuntimeMetamodels { +public interface RuntimeMetamodelsImplementor extends RuntimeMetamodels, MappingContext { @Override MappingMetamodelImplementor getMappingMetamodel(); 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 3a4aa9395f39..0ae78b52ea14 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 @@ -381,7 +381,7 @@ public AbstractCollectionPersister( else { final Column col = (Column) selectable; elementColumnNames[j] = col.getQuotedName( dialect ); - elementColumnWriters[j] = col.getWriteExpr( elementBootDescriptor.getSelectableType( factory, j ), dialect ); + elementColumnWriters[j] = col.getWriteExpr( elementBootDescriptor.getSelectableType( factory.getRuntimeMetamodels(), j ), dialect ); elementColumnReaders[j] = col.getReadExpr( dialect ); elementColumnReaderTemplates[j] = col.getTemplate( dialect, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ResultSetMappingProcessor.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ResultSetMappingProcessor.java index 141aad3e7359..508800ddccb8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ResultSetMappingProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ResultSetMappingProcessor.java @@ -378,7 +378,7 @@ else if ( propertyType instanceof ComponentType componentType ) { final Type[] propertyTypes = componentType.getSubtypes(); int aliasIndex = 0; for ( int i = 0; i < propertyNames.length; i++ ) { - final int columnSpan = propertyTypes[i].getColumnSpan( loadable.getFactory() ); + final int columnSpan = propertyTypes[i].getColumnSpan( loadable.getFactory().getRuntimeMetamodels() ); addFetchBuilder( suffix, loadable, 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 7e289dec3251..a601989225f8 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 @@ -13,31 +13,59 @@ /** * The context in which all SQM creations occur. + *

+ * Since we need to be able to parse and type check queries completely + * outside the usual lifecycle of a Hibernate {@code SessionFactory}, + * it's extremely important that code which builds SQM trees does not + * access the factory or other services or object not exposed by this + * context object. * * @author Steve Ebersole */ @Incubating public interface SqmCreationContext extends BindingContext { + + /** + * The {@link QueryEngine}. + */ QueryEngine getQueryEngine(); + /** + * The {@link NodeBuilder}. + */ default NodeBuilder getNodeBuilder() { return getQueryEngine().getCriteriaBuilder(); } /** + * Obtain a Java class object with the given fully-qualified + * name. This method may only be used for unmanaged types, + * for example, for {@code select new}, or for references to + * {@code static final} constants or to {@code enum} values. + * * @apiNote Avoid calling this method, since {@link Class} * objects are not available to the query validator - * in Hibernate Processor at compilation time. + * in Hibernate Processor at compilation time. If + * you must call it, be prepared to robustly handle + * the case in which the class is not present, in + * which case this method might return something + * arbitrary like {@code Object[].class}. */ default Class classForName(String className) { return getQueryEngine().getClassLoaderService().classForName( className ); } + /** + * The {@link MappingMetamodel}. + */ @Override default MappingMetamodel getMappingMetamodel() { return getQueryEngine().getMappingMetamodel(); } + /** + * The {@link JpaMetamodel}. + */ @Override default JpaMetamodel getJpaMetamodel() { return getQueryEngine().getJpaMetamodel(); 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 590f7cba7c07..5c968ccd9413 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 @@ -13,8 +13,14 @@ import org.hibernate.type.descriptor.WrapperOptions; /** - * The "context" in which creation of SQL AST occurs. Provides + * The "context" in which creation of SQL AST occurs. Provides * access to stuff generally needed when creating SQL AST nodes + *

+ * Because we would like to be able to render SQL during the + * startup cycle, before the {@code SessionFactory} is completely + * initialized, code involved in SQL AST creation and rendering + * should avoid making use of the {@code SessionFactory}. + * Instead, use the objects exposed by this creation context. * * @author Steve Ebersole */ diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedFetchInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedFetchInitializer.java index 748da1898c46..ff758b7201ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedFetchInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedFetchInitializer.java @@ -178,7 +178,7 @@ public void resolveInstance(EntityDelayedFetchInitializerData data) { final String uniqueKeyPropertyName = referencedModelPart.getReferencedPropertyName(); final Type uniqueKeyPropertyType = ( referencedModelPart.getReferencedPropertyName() == null ) ? concreteDescriptor.getIdentifierType() : - session.getFactory() + session.getFactory().getRuntimeMetamodels() .getReferencedPropertyType( concreteDescriptor.getEntityName(), uniqueKeyPropertyName diff --git a/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java b/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java index 6fb192674c95..57209c4d018b 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java @@ -284,7 +284,7 @@ public boolean isDirty(final Object x, final Object y, final boolean[] checkable // null value and empty component are considered equivalent int loc = 0; for ( int i = 0; i < propertySpan; i++ ) { - int len = propertyTypes[i].getColumnSpan( session.getFactory() ); + int len = propertyTypes[i].getColumnSpan( session.getFactory().getRuntimeMetamodels() ); if ( len <= 1 ) { final boolean dirty = ( len == 0 || checkable[loc] ) && propertyTypes[i].isDirty( getPropertyValue( x, i ), getPropertyValue( y, i ), session ); @@ -322,7 +322,7 @@ public boolean isModified( // null value and empty components are considered equivalent int loc = 0; for ( int i = 0; i < propertySpan; i++ ) { - final int len = propertyTypes[i].getColumnSpan( session.getFactory() ); + final int len = propertyTypes[i].getColumnSpan( session.getFactory().getRuntimeMetamodels() ); final boolean[] subcheckable = new boolean[len]; System.arraycopy( checkable, loc, subcheckable, 0, len ); if ( propertyTypes[i].isModified( getPropertyValue( old, i ), @@ -343,7 +343,7 @@ public void nullSafeSet(PreparedStatement st, Object value, int begin, SharedSes for ( int i = 0; i < propertySpan; i++ ) { propertyTypes[i].nullSafeSet( st, subvalues[i], begin, session ); - begin += propertyTypes[i].getColumnSpan( session.getFactory() ); + begin += propertyTypes[i].getColumnSpan( session.getFactory().getRuntimeMetamodels() ); } } @@ -359,7 +359,7 @@ public void nullSafeSet( final Object[] subvalues = nullSafeGetValues( value ); int loc = 0; for ( int i = 0; i < propertySpan; i++ ) { - int len = propertyTypes[i].getColumnSpan( session.getFactory() ); + int len = propertyTypes[i].getColumnSpan( session.getFactory().getRuntimeMetamodels() ); //noinspection StatementWithEmptyBody if ( len == 0 ) { //noop @@ -763,7 +763,7 @@ public Object extract(CallableStatement statement, int startIndex, SharedSession notNull = true; } values[i] = value; - currentIndex += propertyType.getColumnSpan( session.getFactory() ); + currentIndex += propertyType.getColumnSpan( session.getFactory().getRuntimeMetamodels() ); } if ( polymorphic ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/EntityType.java b/hibernate-core/src/main/java/org/hibernate/type/EntityType.java index 122b77b70242..b91cda6ec61a 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/EntityType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/EntityType.java @@ -229,7 +229,7 @@ private Class determineAssociatedEntityClass() { public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SharedSessionContractImplementor session) throws SQLException { if ( settable.length > 0 ) { - requireIdentifierOrUniqueKeyType( session.getFactory() ) + requireIdentifierOrUniqueKeyType( session.getFactory().getRuntimeMetamodels() ) .nullSafeSet( st, getIdentifier( value, session ), index, settable, session ); } } @@ -237,7 +237,7 @@ public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] @Override public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws SQLException { - requireIdentifierOrUniqueKeyType( session.getFactory() ) + requireIdentifierOrUniqueKeyType( session.getFactory().getRuntimeMetamodels() ) .nullSafeSet( st, getIdentifier( value, session ), index, session ); } @@ -275,7 +275,8 @@ else if ( y == null ) { // At this point we know both are non-null. final Object xId = extractIdentifier( x, factory ); final Object yId = extractIdentifier( y, factory ); - return getIdentifierType( factory ).compare( xId, yId ); + return getIdentifierType( factory.getRuntimeMetamodels() ) + .compare( xId, yId ); } } @@ -332,7 +333,7 @@ && isTransient( associatedEntityName, original, Boolean.FALSE, session ) ) { throw new AssertionFailure( "non-transient entity has a null id: " + original.getClass().getName() ); } final Object replaced = - getIdentifierOrUniqueKeyType( session.getFactory() ) + getIdentifierOrUniqueKeyType( session.getFactory().getRuntimeMetamodels() ) .replace( id, null, session, owner, copyCache ); return resolve( replaced, session, owner ); } @@ -574,7 +575,7 @@ public boolean isLogicalOneToOne() { * @return The identifier type * @deprecated use {@link #getIdentifierType(MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) Type getIdentifierType(final Mapping factory) { return getIdentifierType( (MappingContext) factory ); } @@ -603,7 +604,7 @@ Type getIdentifierType(final MappingContext mappingContext) { Type getIdentifierType(final SharedSessionContractImplementor session) { final Type type = associatedIdentifierType; if ( type == null ) { - associatedIdentifierType = getIdentifierType( session.getFactory() ); + associatedIdentifierType = getIdentifierType( session.getFactory().getRuntimeMetamodels() ); return associatedIdentifierType; } else { @@ -624,7 +625,7 @@ Type getIdentifierType(final SharedSessionContractImplementor session) { * or unique key property name. * @deprecated use {@link #getIdentifierOrUniqueKeyType(MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException { return getIdentifierOrUniqueKeyType( (MappingContext) factory ); } @@ -764,7 +765,7 @@ public Object loadByUniqueKey( entityName, uniqueKeyPropertyName, key, - getIdentifierOrUniqueKeyType( factory ), + getIdentifierOrUniqueKeyType( factory.getRuntimeMetamodels() ), session.getFactory() ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java index e9aac6f07629..e392fe3b099d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java @@ -154,7 +154,7 @@ else if ( old == null ) { } else { // the ids are fully resolved, so compare them with isDirty(), not isModified() - return getIdentifierOrUniqueKeyType( session.getFactory() ) + return getIdentifierOrUniqueKeyType( session.getFactory().getRuntimeMetamodels() ) .isDirty( old, getIdentifierEvenIfTransient( current, session ), session ); } } @@ -189,7 +189,8 @@ public Serializable disassemble(Object value, SessionFactoryImplementor sessionF // property-ref, which might not be initialized final Object id = getIdentifier( value, sessionFactory ); checkIdNotNull( id ); - return getIdentifierType( sessionFactory ).disassemble( id, sessionFactory ); + return getIdentifierType( sessionFactory.getRuntimeMetamodels() ) + .disassemble( id, sessionFactory ); } } @@ -242,7 +243,8 @@ public boolean isDirty( else { final Object oldid = getIdentifierEvenIfTransient( old, session ); final Object newid = getIdentifierEvenIfTransient( current, session ); - return getIdentifierOrUniqueKeyType( session.getFactory() ).isDirty( oldid, newid, session ); + return getIdentifierOrUniqueKeyType( session.getFactory().getRuntimeMetamodels() ) + .isDirty( oldid, newid, session ); } } @@ -261,7 +263,8 @@ else if ( isSame( old, current ) ) { else { final Object oldid = getIdentifierEvenIfTransient( old, session ); final Object newid = getIdentifierEvenIfTransient( current, session ); - return getIdentifierOrUniqueKeyType( session.getFactory() ).isDirty( oldid, newid, checkable, session ); + return getIdentifierOrUniqueKeyType( session.getFactory().getRuntimeMetamodels() ) + .isDirty( oldid, newid, checkable, session ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/MappingContext.java b/hibernate-core/src/main/java/org/hibernate/type/MappingContext.java index 6c6bb8ea2d84..fb72c42f50a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/MappingContext.java +++ b/hibernate-core/src/main/java/org/hibernate/type/MappingContext.java @@ -7,13 +7,14 @@ import org.hibernate.MappingException; /** - * Declares operations used by implementors of {@link Type} that are common to - * "compiled" mappings held at runtime by a {@link org.hibernate.SessionFactory} - * and "uncompiled" mappings held by a {@link org.hibernate.cfg.Configuration}. + * Declares operations used by implementors of {@link Type} that are common to the fully-"compiled" + * runtime mapping metadata held by a {@link org.hibernate.SessionFactory} and the incomplete metamodel + * which exists during the {@linkplain org.hibernate.boot.model.process.spi.MetadataBuildingProcess + * metadata building process}. * * @see Type - * @see org.hibernate.internal.SessionFactoryImpl - * @see org.hibernate.cfg.Configuration + * @see org.hibernate.metamodel.spi.RuntimeMetamodelsImplementor + * @see org.hibernate.boot.Metadata * * */ diff --git a/hibernate-core/src/main/java/org/hibernate/type/MetaType.java b/hibernate-core/src/main/java/org/hibernate/type/MetaType.java index 763b96c758bd..93ee26c4b3a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/MetaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/MetaType.java @@ -123,7 +123,7 @@ public String toXMLString(Object value, SessionFactoryImplementor factory) throw /** * @deprecated use {@link #fromXMLString(String, MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) public Object fromXMLString(String xml, Mapping factory) throws HibernateException { return fromXMLString( xml, (MappingContext) factory ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/SpecialOneToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/SpecialOneToOneType.java index d214bc42b2c4..e8c3b3e857e1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/SpecialOneToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/SpecialOneToOneType.java @@ -100,7 +100,7 @@ public Serializable disassemble(Object value, SessionFactoryImplementor sessionF getAssociatedEntityName() ); } - return getIdentifierType( sessionFactory ).disassemble( id, sessionFactory ); + return getIdentifierType( sessionFactory.getRuntimeMetamodels() ).disassemble( id, sessionFactory ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/Type.java b/hibernate-core/src/main/java/org/hibernate/type/Type.java index 8800c70799aa..da6aa6f73ec3 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/Type.java +++ b/hibernate-core/src/main/java/org/hibernate/type/Type.java @@ -103,7 +103,7 @@ public interface Type extends Serializable { * @throws MappingException Generally indicates an issue accessing the passed mapping object. * @deprecated use {@link #getColumnSpan(MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) default int getColumnSpan(Mapping mapping) throws MappingException{ return getColumnSpan( (MappingContext) mapping); } @@ -134,7 +134,7 @@ default int getColumnSpan(Mapping mapping) throws MappingException{ * @throws MappingException Generally indicates an issue accessing the passed mapping object. * @deprecated use {@link #getSqlTypeCodes(MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) default int[] getSqlTypeCodes(Mapping mapping) throws MappingException{ return getSqlTypeCodes((MappingContext) mapping); } @@ -544,7 +544,7 @@ String toLoggableString(@Nullable Object value, SessionFactoryImplementor factor * @return array indicating column nullness for a value instance * @deprecated use {@link #toColumnNullness(Object, MappingContext)} */ - @Deprecated(since = "7.0") + @Deprecated(since = "7.0", forRemoval = true) default boolean[] toColumnNullness(@Nullable Object value, Mapping mapping){ return toColumnNullness( value,(MappingContext) mapping); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/internal/ValidityAuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/internal/ValidityAuditStrategy.java index c938c1bafb63..c2bbd95aea10 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/internal/ValidityAuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/internal/ValidityAuditStrategy.java @@ -695,7 +695,7 @@ public QueryParameterBindingType(Object value, Type type) { public int bind(int index, PreparedStatement statement, SessionImplementor session) throws SQLException { type.nullSafeSet( statement, value, index, session ); - return type.getColumnSpan( session.getSessionFactory() ); + return type.getColumnSpan( session.getSessionFactory().getRuntimeMetamodels() ); } } 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 1ec029187dc5..202f6bd84d86 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 @@ -54,7 +54,6 @@ import org.hibernate.metamodel.internal.JpaStaticMetamodelPopulationSetting; import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.internal.MetadataContext; -import org.hibernate.metamodel.internal.RuntimeMetamodelsImpl; import org.hibernate.metamodel.mapping.EntityIdentifierMapping; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.model.domain.BasicDomainType; @@ -143,7 +142,7 @@ public abstract class MockSessionFactory implements SessionFactoryImplementor, SessionFactoryOptions, QueryEngine, FunctionContributions, MetadataBuildingOptions, MetadataBuildingContext, RuntimeModelCreationContext, BootstrapContext, - JdbcTypeIndicators { + JdbcTypeIndicators, RuntimeMetamodelsImplementor { private static final BasicTypeImpl OBJECT_BASIC_TYPE = new BasicTypeImpl<>(new UnknownBasicJavaType<>(Object.class), ObjectJdbcType.INSTANCE); @@ -532,10 +531,7 @@ public MappingMetamodelImplementor getMappingMetamodel() { @Override public RuntimeMetamodelsImplementor getRuntimeMetamodels() { - final RuntimeMetamodelsImpl runtimeMetamodels = new RuntimeMetamodelsImpl(); - runtimeMetamodels.setJpaMetamodel( metamodel.getJpaMetamodel() ); - runtimeMetamodels.setMappingMetamodel( metamodel ); - return runtimeMetamodels; + return this; } @Override