HHH-18551 Fix memory leak caused by creation of new BasicTypeImpl

This commit is contained in:
Piotr Wolny 2024-09-02 15:02:13 +02:00 committed by Christian Beikov
parent cc72efd0fe
commit b179881847
4 changed files with 8 additions and 9 deletions

View File

@ -44,7 +44,6 @@ import org.hibernate.jpa.spi.JpaCompliance;
import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.metamodel.model.domain.JpaMetamodel;
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
import org.hibernate.metamodel.model.domain.internal.BasicTypeImpl;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.query.BindableType;
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
@ -1540,7 +1539,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, Serializable {
final EnumJavaType javaType = new EnumJavaType<>( type );
final JdbcType jdbcType =
javaType.getRecommendedJdbcType( typeConfiguration.getCurrentBaseSqlTypeIndicators() );
return new BasicTypeImpl<>( javaType, jdbcType );
return typeConfiguration.getBasicTypeRegistry().resolve( javaType, jdbcType );
}
else {
return result;

View File

@ -16,7 +16,6 @@ import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.MappingModelExpressible;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.SqlExpressible;
import org.hibernate.metamodel.model.domain.internal.BasicTypeImpl;
import org.hibernate.query.BindableType;
import org.hibernate.sql.ast.SqlAstWalker;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
@ -25,6 +24,7 @@ import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcParameterBinder;
import org.hibernate.sql.exec.spi.JdbcParameterBinding;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.EnumJavaType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
@ -133,7 +133,7 @@ public abstract class AbstractJdbcParameter
}
}
private static <E extends Enum<E>> BasicTypeImpl<E> createEnumType(ExecutionContext executionContext, Class<E> enumClass) {
private static <E extends Enum<E>> BasicType<E> createEnumType(ExecutionContext executionContext, Class<E> enumClass) {
final EnumJavaType<E> enumJavaType = new EnumJavaType<>( enumClass );
final JdbcTypeIndicators indicators =
executionContext.getSession().getTypeConfiguration().getCurrentBaseSqlTypeIndicators();
@ -142,7 +142,7 @@ public abstract class AbstractJdbcParameter
// so just accept the default from the TypeConfiguration, which
// is usually ORDINAL (the default according to JPA)
enumJavaType.getRecommendedJdbcType(indicators);
return new BasicTypeImpl<>( enumJavaType, jdbcType );
return indicators.getTypeConfiguration().getBasicTypeRegistry().resolve( enumJavaType, jdbcType );
}
@Override

View File

@ -18,7 +18,6 @@ import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
import org.hibernate.type.descriptor.java.spi.UnknownBasicJavaType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
import org.hibernate.type.internal.BasicTypeImpl;
import org.hibernate.type.spi.TypeConfiguration;
public abstract class AbstractArrayJavaType<T, E> extends AbstractClassJavaType<T>
@ -47,7 +46,8 @@ public abstract class AbstractArrayJavaType<T, E> extends AbstractClassJavaType<
// Always determine the recommended type to make sure this is a valid basic java type
return indicators.getTypeConfiguration().getJdbcTypeRegistry().resolveTypeConstructorDescriptor(
indicators.getPreferredSqlTypeCodeForArray(),
new BasicTypeImpl<>( componentJavaType, componentJavaType.getRecommendedJdbcType( indicators ) ),
indicators.getTypeConfiguration().getBasicTypeRegistry().resolve(
componentJavaType, componentJavaType.getRecommendedJdbcType( indicators ) ),
ColumnTypeInformation.EMPTY
);
}

View File

@ -38,7 +38,6 @@ import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.MutabilityPlan;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
import org.hibernate.type.internal.BasicTypeImpl;
import org.hibernate.type.spi.TypeConfiguration;
/**
@ -76,7 +75,8 @@ public class BasicCollectionJavaType<C extends Collection<E>, E> extends Abstrac
// (even though we only use this inside the if block, we want it to throw here if something wrong)
return indicators.getTypeConfiguration().getJdbcTypeRegistry().resolveTypeConstructorDescriptor(
indicators.getPreferredSqlTypeCodeForArray(),
new BasicTypeImpl<>( componentJavaType, componentJavaType.getRecommendedJdbcType( indicators ) ),
indicators.getTypeConfiguration().getBasicTypeRegistry().resolve(
componentJavaType, componentJavaType.getRecommendedJdbcType( indicators ) ),
ColumnTypeInformation.EMPTY
);
}