Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions hibernate-core/src/main/java/org/hibernate/boot/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.UUID;
import java.util.function.Consumer;

import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import org.hibernate.boot.model.NamedEntityGraphDefinition;
Expand All @@ -27,6 +28,8 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.type.Type;
import org.hibernate.type.spi.TypeConfiguration;

/**
* Represents the ORM model as determined by aggregating the provided mapping sources.
Expand Down Expand Up @@ -203,4 +206,12 @@ public interface Metadata extends Mapping {
* All of the known model contributors
*/
Set<String> getContributors();

TypeConfiguration getTypeConfiguration();

Type getIdentifierType(String className) throws org.hibernate.MappingException;

String getIdentifierPropertyName(String className);

Type getReferencedPropertyType(String className, String propertyName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public void validate() throws MappingException {
}

for ( Collection collectionBinding : this.getCollectionBindings() ) {
collectionBinding.validate( this );
collectionBinding.validate( getTypeConfiguration() );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ else if ( value instanceof Collection ) {
}

private boolean isAggregateArray() {
switch ( component.getAggregateColumn().getSqlTypeCode( context.getMetadataCollector() ) ) {
switch ( component.getAggregateColumn().getSqlTypeCode( context.getMetadataCollector().getTypeConfiguration() ) ) {
case SqlTypes.STRUCT_ARRAY:
case SqlTypes.STRUCT_TABLE:
case SqlTypes.JSON_ARRAY:
Expand Down Expand Up @@ -386,7 +386,7 @@ private static void ensureChildrenInitialized(
AggregateColumn aggregateColumn) {
for ( Column aggregatedColumn : aggregateColumn.getComponent().getAggregatedColumns() ) {
// Make sure this state is initialized
aggregatedColumn.getSqlTypeCode( metadataCollector );
aggregatedColumn.getSqlTypeCode( metadataCollector.getTypeConfiguration() );
aggregatedColumn.getSqlType( metadataCollector );
if ( aggregatedColumn instanceof AggregateColumn ) {
ensureChildrenInitialized( metadataCollector, (AggregateColumn) aggregatedColumn );
Expand All @@ -402,7 +402,7 @@ private static void ensureParentInitialized(
// Trigger resolving of the value so that the column gets properly filled
aggregateColumn.getValue().getType();
// Make sure this state is initialized
aggregateColumn.getSqlTypeCode( metadataCollector );
aggregateColumn.getSqlTypeCode( metadataCollector.getTypeConfiguration() );
aggregateColumn.getSqlType( metadataCollector );
aggregateColumn = aggregateColumn.getComponent().getParentAggregateColumn();
} while ( aggregateColumn != null );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hibernate.mapping.Table;
import org.hibernate.mapping.UniqueKey;
import org.hibernate.mapping.UserDefinedObjectType;
import org.hibernate.type.spi.TypeConfiguration;

import static java.lang.Math.log;
import static org.hibernate.type.SqlTypes.*;
Expand Down Expand Up @@ -80,14 +81,15 @@ protected ColumnComparator(Metadata metadata) {
@Override
public int compare(Column o1, Column o2) {
final Dialect dialect = metadata.getDatabase().getDialect();
final TypeConfiguration typeConfiguration = metadata.getTypeConfiguration();
final int physicalSizeInBytes1 = physicalSizeInBytes(
o1.getSqlTypeCode( metadata ),
o1.getColumnSize( dialect, metadata ),
o1.getSqlTypeCode( typeConfiguration ),
o1.getColumnSize( dialect, typeConfiguration ),
metadata
);
final int physicalSizeInBytes2 = physicalSizeInBytes(
o2.getSqlTypeCode( metadata ),
o2.getColumnSize( dialect, metadata ),
o2.getSqlTypeCode( typeConfiguration ),
o2.getColumnSize( dialect, typeConfiguration ),
metadata
);
int cmp = Integer.compare( Integer.max( physicalSizeInBytes1, 4 ), Integer.max( physicalSizeInBytes2, 4 ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ private static void appendSerializer(List<Column> aggregatedColumns, StringBuild
}
else if ( needsVarcharForBitDataCast( udtColumn.getSqlType() ) ) {
serializerSb.append( ",cast(" ).append( prefix ).append( udtColumn.getName() ).append( " as varchar(" )
.append( udtColumn.getColumnSize( null, null ).getLength() ).append( ") for bit data)" );
.append( udtColumn.getSize().getLength() )
.append( ") for bit data)" );
}
else {
serializerSb.append( ',' ).append( prefix ).append( udtColumn.getName() );
Expand Down Expand Up @@ -456,7 +457,7 @@ private static void appendDeserializerColumns(
deserializerSb.append( prefix ).append( udtColumn.getName() ).append( ' ' );
if ( needsVarcharForBitDataCast( udtColumn.getSqlType() ) ) {
deserializerSb.append( "varchar(" )
.append( udtColumn.getColumnSize( null, null ).getLength() ).append( ") for bit data" );
.append( udtColumn.getSize().getLength() ).append( ") for bit data" );
}
else {
deserializerSb.append( udtColumn.getSqlType() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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.getTypeConfiguration() ) + 1,
session
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,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.getTypeConfiguration() );

if ( lockable.isVersioned() ) {
lockable.getVersionType().nullSafeSet( st, version, offset, session );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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.getTypeConfiguration() );

if ( lockable.isVersioned() ) {
lockable.getVersionType().nullSafeSet( st, version, offset, session );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void lock(

final Type lockableIdentifierType = lockable.getIdentifierType();
lockableIdentifierType.nullSafeSet( st, id, offset, session );
offset += lockableIdentifierType.getColumnSpan( factory );
offset += lockableIdentifierType.getColumnSpan( factory.getTypeConfiguration() );

if ( lockable.isVersioned() ) {
lockableVersionType.nullSafeSet( st, version, offset, session );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static TemporaryTable createIdTable(
),
column.getColumnSize(
dialect,
runtimeModelCreationContext.getMetadata()
runtimeModelCreationContext.getTypeConfiguration()
),
column.isNullable(),
true
Expand Down Expand Up @@ -238,7 +238,7 @@ public static TemporaryTable createIdTable(
),
column.getColumnSize(
dialect,
runtimeModelCreationContext.getMetadata()
runtimeModelCreationContext.getMetadata().getTypeConfiguration()
),
column.isNullable()
)
Expand Down Expand Up @@ -324,7 +324,7 @@ public static TemporaryTable createEntityTable(
if ( dialect.getIdentityColumnSupport().hasDataTypeInIdentityColumn() ) {
sqlTypeName = column.getSqlType( runtimeModelCreationContext.getMetadata() ) + " ";
}
sqlTypeName = sqlTypeName + dialect.getIdentityColumnSupport().getIdentityColumnString( column.getSqlTypeCode( runtimeModelCreationContext.getMetadata() ) );
sqlTypeName = sqlTypeName + dialect.getIdentityColumnSupport().getIdentityColumnString( column.getSqlTypeCode( runtimeModelCreationContext.getMetadata().getTypeConfiguration() ) );
columns.add(
new TemporaryTableColumn(
temporaryTable,
Expand All @@ -333,7 +333,7 @@ public static TemporaryTable createEntityTable(
sqlTypeName,
column.getColumnSize(
dialect,
runtimeModelCreationContext.getMetadata()
runtimeModelCreationContext.getMetadata().getTypeConfiguration()
),
// Always report as nullable as the identity column string usually includes the not null constraint
true,//column.isNullable()
Expand Down Expand Up @@ -365,7 +365,7 @@ public static TemporaryTable createEntityTable(
),
column.getColumnSize(
dialect,
runtimeModelCreationContext.getMetadata()
runtimeModelCreationContext.getMetadata().getTypeConfiguration()
),
// We have to set the identity column after the root table insert
column.isNullable() || identityColumn || hasOptimizer,
Expand All @@ -387,7 +387,7 @@ public static TemporaryTable createEntityTable(
),
discriminator.getColumnSize(
dialect,
runtimeModelCreationContext.getMetadata()
runtimeModelCreationContext.getMetadata().getTypeConfiguration()
),
// We have to set the identity column after the root table insert
discriminator.isNullable()
Expand Down Expand Up @@ -418,7 +418,7 @@ public static TemporaryTable createEntityTable(
),
column.getColumnSize(
dialect,
runtimeModelCreationContext.getMetadata()
runtimeModelCreationContext.getMetadata().getTypeConfiguration()
),
// Treat regular temporary table columns as nullable for simplicity
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.hibernate.CustomEntityDirtinessStrategy;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
Expand All @@ -31,6 +32,7 @@
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
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;
Expand Down Expand Up @@ -189,4 +191,16 @@ default MappingMetamodelImplementor getMappingMetamodel() {
*/
@Override @Deprecated
MetamodelImplementor getMetamodel();

default Type getIdentifierType(String className) throws MappingException{
return getMappingMetamodel().getEntityDescriptor( className ).getIdentifierType();
}

default String getIdentifierPropertyName(String className) throws MappingException{
return getMappingMetamodel().getEntityDescriptor( className ).getIdentifierPropertyName();
}

default Type getReferencedPropertyType(String className, String propertyName) throws MappingException{
return getMappingMetamodel().getEntityDescriptor( className ).getPropertyType( propertyName );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [EntityPersister.getPropertyType](1) should be avoided because it has been deprecated.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static CurrentTimestampGeneratorDelegate getGeneratorDelegate(
final BasicValue basicValue = (BasicValue) context.getProperty().getValue();
final Size size = basicValue.getColumns().get( 0 ).getColumnSize(
context.getDatabase().getDialect(),
basicValue.getMetadata()
basicValue.getMetadata().getTypeConfiguration()
);
final Clock baseClock = context.getServiceRegistry()
.requireService( ConfigurationService.class )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.BasicType;
import org.hibernate.type.Type;
import org.hibernate.type.spi.TypeConfiguration;

/**
* @author Steve Ebersole
Expand Down Expand Up @@ -152,6 +153,11 @@ public boolean isValid(Mapping mapping) throws MappingException {
return false;
}

@Override
public boolean isValid(TypeConfiguration typeConfiguration) throws MappingException {
return false;
}

@Override
public void setTypeUsingReflection(String className, String propertyName) throws MappingException {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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().getTypeConfiguration() );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ 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.getTypeConfiguration() );
this.sqlBatchSize = sessionFactory.getJdbcServices()
.getDialect()
.getBatchLoadSizingStrategy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public <T> EntityBatchLoader<T> 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.getTypeConfiguration() ) == 1
&& supportsSqlArrayType( factory.getJdbcServices().getDialect() )
&& identifierType instanceof BasicType ) {
// we can use a single ARRAY parameter to send all the ids
Expand Down
25 changes: 23 additions & 2 deletions hibernate-core/src/main/java/org/hibernate/mapping/Any.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hibernate.engine.spi.Mapping;
import org.hibernate.type.AnyType;
import org.hibernate.type.Type;
import org.hibernate.type.spi.TypeConfiguration;

/**
* A mapping model object representing a {@linkplain org.hibernate.annotations.Any polymorphic association}
Expand Down Expand Up @@ -250,13 +251,22 @@ private String getTypeNameOrNull(SimpleValue simpleValue) {
return simpleValue != null ? simpleValue.getTypeName() : null;
}

@Override
public boolean isValid(Mapping mapping) throws MappingException {
if ( discriminatorDescriptor != null ) {
return discriminatorDescriptor.isValid( mapping ) && keyDescriptor.isValid( mapping );
}
return metaMapping.isValid( mapping ) && keyMapping.isValid( mapping );
}

@Override
public boolean isValid(TypeConfiguration typeConfiguration) throws MappingException {
if ( discriminatorDescriptor != null ) {
return discriminatorDescriptor.isValid( typeConfiguration ) && keyDescriptor.isValid( typeConfiguration );
}
return metaMapping.isValid( typeConfiguration ) && keyMapping.isValid( typeConfiguration );
}

private static String columnName(Column column, MetadataBuildingContext buildingContext) {
final JdbcServices jdbcServices = buildingContext
.getBootstrapContext()
Expand Down Expand Up @@ -391,10 +401,16 @@ public void addFormula(Formula formula) {
}

@Override
public boolean isValid(Mapping mapping) {
public boolean isValid(Mapping mapping) throws MappingException {
return columnName != null
&& getType().getColumnSpan( mapping ) == 1;
}

@Override
public boolean isValid(TypeConfiguration typeConfiguration) {
return columnName != null
&& getType().getColumnSpan( typeConfiguration ) == 1;
}
}

public static class KeyValue extends SimpleValue {
Expand Down Expand Up @@ -466,8 +482,13 @@ public void addFormula(Formula formula) {

@Override
public boolean isValid(Mapping mapping) throws MappingException {
// check
return super.isValid( mapping );
}

@Override
public boolean isValid(TypeConfiguration typeConfiguration) throws MappingException {
// check
return super.isValid( typeConfiguration );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public Resolution<?> resolve() {
final Size size;
if ( selectable instanceof Column column ) {
resolveColumn( column, getDialect() );
size = column.calculateColumnSize( getDialect(), getBuildingContext().getMetadataCollector() );
size = column.calculateColumnSize( getDialect(), getBuildingContext().getMetadataCollector().getTypeConfiguration() );
}
else {
size = Size.nil();
Expand Down Expand Up @@ -990,7 +990,7 @@ public int resolveJdbcTypeCode(int jdbcTypeCode) {
return aggregateColumn == null
? jdbcTypeCode
: getDialect().getAggregateSupport()
.aggregateComponentSqlTypeCode( aggregateColumn.getSqlTypeCode( getMetadata() ), jdbcTypeCode );
.aggregateComponentSqlTypeCode( aggregateColumn.getSqlTypeCode( getMetadata().getTypeConfiguration() ), jdbcTypeCode );
}

@Override
Expand Down
Loading