From b62c23ab29f428a8d0f3ff5ed3efa49b804d356e Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Sat, 8 Jan 2022 10:05:24 -0600 Subject: [PATCH] HHH-15017 - Clean-up Query#setParameter overloads - https://hibernate.atlassian.net/browse/HHH-15017 --- .../dialect/function/CastStrEmulation.java | 2 +- .../function/CoalesceIfnullEmulation.java | 2 +- .../function/CommonFunctionFactory.java | 2 +- .../dialect/function/ExtractFunction.java | 2 +- .../InsertSubstringOverlayEmulation.java | 2 +- .../function/LocatePositionEmulation.java | 2 +- .../function/LpadRpadPadEmulation.java | 2 +- .../function/NvlCoalesceEmulation.java | 2 +- .../dialect/function/StandardSQLFunction.java | 2 +- .../function/TimestampaddFunction.java | 2 +- .../function/TimestampdiffFunction.java | 2 +- .../function/TransactSQLStrFunction.java | 2 +- .../spi/AbstractParameterDescriptor.java | 20 +- .../query/spi/NamedParameterDescriptor.java | 8 +- .../query/spi/OrdinalParameterDescriptor.java | 6 +- .../spi/SessionFactoryDelegatingImpl.java | 2 +- .../internal/parse/PathQualifierType.java | 3 +- .../internal/SessionFactoryImpl.java | 2 +- .../hibernate/metamodel/MappingMetamodel.java | 2 +- .../metamodel/internal/AttributeFactory.java | 89 +- .../internal/PluralAttributeMetadata.java | 6 +- .../model/domain/AbstractDomainType.java | 5 + .../model/domain/AllowableParameterType.java | 21 - .../model/domain/BasicDomainType.java | 2 + .../model/domain/EmbeddableDomainType.java | 6 +- .../model/domain/ManagedDomainType.java | 6 +- .../model/domain/PersistentAttribute.java | 2 +- .../domain/PluralPersistentAttribute.java | 2 +- .../model/domain/SimpleDomainType.java | 4 + .../domain/SingularPersistentAttribute.java | 4 +- .../domain/internal/AbstractAttribute.java | 9 +- .../internal/AbstractSqmPathSource.java | 10 +- .../internal/AnyMappingDomainTypeImpl.java | 2 +- .../internal/AnyMappingSqmPathSource.java | 13 +- .../model/domain/internal/ArrayTupleType.java | 10 +- .../domain/internal/BasicSqmPathSource.java | 4 +- .../model/domain/internal/BasicTypeImpl.java | 2 - .../internal/DiscriminatorSqmPathSource.java | 4 +- .../domain/internal/EmbeddableTypeImpl.java | 4 +- .../internal/EmbeddedSqmPathSource.java | 12 +- .../domain/internal/EntitySqmPathSource.java | 2 - .../model/domain/internal/EntityTypeImpl.java | 5 - .../domain/internal/MappingMetamodelImpl.java | 2 +- .../internal/PluralAttributeBuilder.java | 44 +- .../internal/SingularAttributeImpl.java | 3 +- .../internal/FunctionReturnImpl.java | 4 +- .../NamedCallableQueryMementoImpl.java | 2 +- .../procedure/internal/ProcedureCallImpl.java | 91 +- .../internal/ProcedureParamBindings.java | 10 +- .../ProcedureParameterBindingImpl.java | 18 +- .../internal/ProcedureParameterImpl.java | 7 +- .../query/AbstractQueryParameter.java | 3 +- .../AllowableFunctionReturnType.java | 4 +- .../AllowableOutputParameterType.java | 3 +- .../query/AllowableParameterType.java | 62 + .../java/org/hibernate/query/NativeQuery.java | 198 ++- .../hibernate/query/ParameterMetadata.java | 1 - .../main/java/org/hibernate/query/Query.java | 664 +++++----- .../org/hibernate/query/QueryParameter.java | 1 - .../hibernate/query/TypedParameterValue.java | 3 +- .../criteria/HibernateCriteriaBuilder.java | 59 - .../hql/internal/SemanticQueryBuilder.java | 2 +- .../internal/AbstractQueryParameterImpl.java | 9 +- .../query/internal/BindingTypeHelper.java | 23 +- .../query/internal/ParameterMetadataImpl.java | 2 +- .../internal/QueryParameterBindingImpl.java | 81 +- .../internal/QueryParameterBindingsImpl.java | 2 +- .../internal/QueryParameterNamedImpl.java | 2 +- .../QueryParameterPositionalImpl.java | 2 +- .../hibernate/query/spi/AbstractQuery.java | 1100 ++++++++++------- .../hibernate/query/spi/QueryImplementor.java | 125 ++ .../query/spi/QueryParameterBinding.java | 2 +- .../QueryParameterBindingTypeResolver.java | 2 +- .../spi/QueryParameterBindingValidator.java | 57 +- .../query/spi/QueryParameterImplementor.java | 4 +- .../query/spi/QueryParameterListBinding.java | 2 +- .../query/sql/internal/NativeQueryImpl.java | 472 ++++--- .../query/sql/spi/NativeQueryImplementor.java | 231 ++-- .../org/hibernate/query/sqm/NodeBuilder.java | 66 +- .../hibernate/query/sqm/SqmExpressable.java | 9 +- .../AbstractSqmFunctionDescriptor.java | 2 +- ...actSqmSelfRenderingFunctionDescriptor.java | 2 +- .../JdbcEscapeFunctionDescriptor.java | 2 +- .../MultipatternSqmFunctionDescriptor.java | 2 +- ...ringAggregateFunctionSqlAstExpression.java | 2 +- ...SelfRenderingFunctionSqlAstExpression.java | 4 +- .../SelfRenderingSqmAggregateFunction.java | 2 +- .../function/SelfRenderingSqmFunction.java | 2 +- .../sqm/function/SqmFunctionDescriptor.java | 2 +- .../sqm/internal/SqmCriteriaNodeBuilder.java | 97 +- .../function/FunctionReturnTypeResolver.java | 2 +- .../StandardFunctionReturnTypeResolvers.java | 2 +- .../sqm/sql/BaseSqmToSqlAstConverter.java | 119 +- .../internal/SqmParameterInterpretation.java | 60 +- .../tree/domain/SqmBasicValuedSimplePath.java | 19 +- .../domain/SqmEmbeddedValuedSimplePath.java | 33 +- .../domain/SqmEntityValuedSimplePath.java | 7 +- .../sqm/tree/domain/SqmMapEntryReference.java | 14 +- .../tree/expression/AbstractSqmParameter.java | 11 +- .../tree/expression/JpaCriteriaParameter.java | 27 +- .../tree/expression/NullSqmExpressable.java | 30 + .../sqm/tree/expression/SqmCastTarget.java | 2 +- .../sqm/tree/expression/SqmDurationUnit.java | 2 +- .../sqm/tree/expression/SqmEnumLiteral.java | 11 +- .../sqm/tree/expression/SqmExpression.java | 2 +- ...alHelper.java => SqmExpressionHelper.java} | 32 +- .../sqm/tree/expression/SqmExtractUnit.java | 2 +- .../sqm/tree/expression/SqmFieldLiteral.java | 14 +- .../SqmJpaCriteriaParameterWrapper.java | 19 +- .../sqm/tree/expression/SqmLiteralNull.java | 2 +- .../tree/expression/SqmNamedParameter.java | 4 +- .../sqm/tree/expression/SqmParameter.java | 5 +- .../SqmParameterizedEntityType.java | 2 +- .../expression/SqmPositionalParameter.java | 4 +- .../sqm/tree/expression/SqmToDuration.java | 2 +- .../sqm/tree/jpa/ParameterCollector.java | 2 +- .../tree/select/SqmDynamicInstantiation.java | 7 +- .../tree/select/SqmJpaCompoundSelection.java | 6 +- .../exec/internal/AbstractJdbcParameter.java | 2 +- .../internal/JdbcCallFunctionReturnImpl.java | 2 +- .../JdbcCallParameterExtractorImpl.java | 2 +- .../JdbcCallParameterRegistrationImpl.java | 2 +- .../spi/JdbcCallParameterRegistration.java | 2 +- .../sql/exec/spi/JdbcParameterBindings.java | 39 +- .../hibernate/type/BasicTypeReference.java | 18 +- .../org/hibernate/type/BasicTypeRegistry.java | 2 +- .../org/hibernate/type/ComponentType.java | 19 +- .../ProcedureParameterExtractionAware.java | 2 +- .../type/SerializableToBlobType.java | 5 +- .../hibernate/type/StandardBasicTypes.java | 6 +- .../hibernate/type/spi/TypeConfiguration.java | 48 +- .../CriteriaQueryTypeQueryAdapterTest.java | 4 +- .../converted/converter/ConverterTest.java | 2 +- .../converter/LongToDateConversionTest.java | 18 +- .../orm/test/query/hql/SelectClauseTests.java | 3 +- .../query/sql/NativeQueryParameterTests.java | 16 +- .../orm/test/type/contributor/ArrayType.java | 23 +- .../function/OrderByFragmentFunction.java | 2 +- .../dialect/hana/HANASpatialAggregate.java | 2 - .../dialect/hana/HANASpatialFunction.java | 1 - .../oracle/OracleSpatialFunctions.java | 1 - .../dialect/oracle/SDOObjectProperty.java | 2 +- .../dialect/oracle/WrappedOGCFunction.java | 1 - 143 files changed, 2292 insertions(+), 2154 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableParameterType.java rename hibernate-core/src/main/java/org/hibernate/{metamodel/model/domain => query}/AllowableFunctionReturnType.java (82%) rename hibernate-core/src/main/java/org/hibernate/{metamodel/model/domain => query}/AllowableOutputParameterType.java (96%) create mode 100644 hibernate-core/src/main/java/org/hibernate/query/AllowableParameterType.java create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/NullSqmExpressable.java rename hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/{LiteralHelper.java => SqmExpressionHelper.java} (69%) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java index e0ec1ee10a..de405e0ba2 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CastStrEmulation.java @@ -6,7 +6,7 @@ */ package org.hibernate.dialect.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor; import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CoalesceIfnullEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CoalesceIfnullEmulation.java index 9a8eb5873d..f0d0221ea1 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CoalesceIfnullEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CoalesceIfnullEmulation.java @@ -6,7 +6,7 @@ */ package org.hibernate.dialect.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor; import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java index 1bd2895796..ec5070f0c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java @@ -16,7 +16,7 @@ import java.util.function.Supplier; import org.hibernate.dialect.Dialect; import org.hibernate.metamodel.mapping.BasicValuedMapping; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.query.spi.QueryEngine; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/ExtractFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/ExtractFunction.java index d9bd670bc2..eb9bca7749 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/ExtractFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/ExtractFunction.java @@ -7,7 +7,7 @@ package org.hibernate.dialect.function; import org.hibernate.dialect.Dialect; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.SemanticException; import org.hibernate.query.TemporalUnit; import org.hibernate.query.spi.QueryEngine; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java index e8e091b82f..62970fa2e1 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/InsertSubstringOverlayEmulation.java @@ -6,7 +6,7 @@ */ package org.hibernate.dialect.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.BinaryArithmeticOperator; import org.hibernate.query.ComparisonOperator; import org.hibernate.query.spi.QueryEngine; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java index a0b7546f30..7afb1fcb71 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/LocatePositionEmulation.java @@ -6,7 +6,7 @@ */ package org.hibernate.dialect.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor; import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java index fd3154e0f1..c90e21b7f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/LpadRpadPadEmulation.java @@ -6,7 +6,7 @@ */ package org.hibernate.dialect.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.TrimSpec; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/NvlCoalesceEmulation.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/NvlCoalesceEmulation.java index 028d20c935..a51a7bca5c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/NvlCoalesceEmulation.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/NvlCoalesceEmulation.java @@ -6,7 +6,7 @@ */ package org.hibernate.dialect.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor; import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java index c289fd604c..8e4d81a8fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java @@ -10,7 +10,7 @@ import java.util.List; import java.util.function.Supplier; import org.hibernate.metamodel.mapping.BasicValuedMapping; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.sqm.function.NamedSqmFunctionDescriptor; import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver; import org.hibernate.query.sqm.tree.SqmTypedNode; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampaddFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampaddFunction.java index fa0eeedab9..4e60830688 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampaddFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampaddFunction.java @@ -9,7 +9,7 @@ package org.hibernate.dialect.function; import org.hibernate.dialect.Dialect; import org.hibernate.metamodel.mapping.BasicValuedMapping; import org.hibernate.metamodel.mapping.JdbcMapping; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.BinaryArithmeticOperator; import org.hibernate.query.TemporalUnit; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampdiffFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampdiffFunction.java index bd8ae00215..90ec30081e 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampdiffFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/TimestampdiffFunction.java @@ -9,7 +9,7 @@ package org.hibernate.dialect.function; import java.util.List; import org.hibernate.dialect.Dialect; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; import org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression; import org.hibernate.query.sqm.produce.function.ArgumentTypesValidator; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java index e90c5b6b5c..69076ff2ec 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/TransactSQLStrFunction.java @@ -8,7 +8,7 @@ package org.hibernate.dialect.function; import java.util.List; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.FunctionRenderingSupport; import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/AbstractParameterDescriptor.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/AbstractParameterDescriptor.java index 0508424397..227620c022 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/AbstractParameterDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/AbstractParameterDescriptor.java @@ -7,7 +7,7 @@ package org.hibernate.engine.query.spi; import org.hibernate.Incubating; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.internal.EntityTypeImpl; import org.hibernate.query.QueryParameter; @@ -18,12 +18,12 @@ import org.hibernate.query.QueryParameter; * @author Steve Ebersole */ @Incubating -public abstract class AbstractParameterDescriptor implements QueryParameter { +public abstract class AbstractParameterDescriptor implements QueryParameter { private final int[] sourceLocations; - private AllowableParameterType expectedType; + private AllowableParameterType expectedType; - public AbstractParameterDescriptor(int[] sourceLocations, AllowableParameterType expectedType) { + public AbstractParameterDescriptor(int[] sourceLocations, AllowableParameterType expectedType) { this.sourceLocations = sourceLocations; this.expectedType = expectedType; } @@ -39,28 +39,28 @@ public abstract class AbstractParameterDescriptor implements QueryParameter { } @Override - public Class getParameterType() { - return expectedType == null ? null : expectedType.getExpressableJavaTypeDescriptor().getJavaTypeClass(); + public Class getParameterType() { + return expectedType == null ? null : expectedType.getBindableJavaType(); } @Override - public AllowableParameterType getHibernateType() { + public AllowableParameterType getHibernateType() { return getExpectedType(); } - public AllowableParameterType getExpectedType() { + public AllowableParameterType getExpectedType() { return expectedType; } - public void resetExpectedType(AllowableParameterType expectedType) { + public void resetExpectedType(AllowableParameterType expectedType) { this.expectedType = expectedType; } @Override public boolean allowsMultiValuedBinding() { if ( expectedType instanceof EntityTypeImpl ) { - return ( (EntityTypeImpl) expectedType ).getIdType() instanceof EmbeddableDomainType; + return ( (EntityTypeImpl) expectedType ).getIdType() instanceof EmbeddableDomainType; } return expectedType instanceof EmbeddableDomainType; } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/NamedParameterDescriptor.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/NamedParameterDescriptor.java index b36ebedae3..44c91e9560 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/NamedParameterDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/NamedParameterDescriptor.java @@ -7,7 +7,7 @@ package org.hibernate.engine.query.spi; import org.hibernate.Incubating; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; /** * Descriptor regarding a named parameter. @@ -15,7 +15,7 @@ import org.hibernate.metamodel.model.domain.AllowableParameterType; * @author Steve Ebersole */ @Incubating -public class NamedParameterDescriptor extends AbstractParameterDescriptor { +public class NamedParameterDescriptor extends AbstractParameterDescriptor { private final String name; /** @@ -25,7 +25,7 @@ public class NamedParameterDescriptor extends AbstractParameterDescriptor { * @param expectedType The expected type of the parameter, according to the translator * @param sourceLocations The locations of the named parameters (aye aye aye) */ - public NamedParameterDescriptor(String name, AllowableParameterType expectedType, int[] sourceLocations) { + public NamedParameterDescriptor(String name, AllowableParameterType expectedType, int[] sourceLocations) { super( sourceLocations, expectedType ); this.name = name; } @@ -44,7 +44,7 @@ public class NamedParameterDescriptor extends AbstractParameterDescriptor { return false; } - NamedParameterDescriptor that = (NamedParameterDescriptor) o; + final NamedParameterDescriptor that = (NamedParameterDescriptor) o; return getName().equals( that.getName() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/OrdinalParameterDescriptor.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/OrdinalParameterDescriptor.java index 4e91a4e102..93e0dc8f8f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/OrdinalParameterDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/OrdinalParameterDescriptor.java @@ -7,7 +7,7 @@ package org.hibernate.engine.query.spi; import org.hibernate.Incubating; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; /** * Descriptor regarding an ordinal parameter. @@ -15,7 +15,7 @@ import org.hibernate.metamodel.model.domain.AllowableParameterType; * @author Steve Ebersole */ @Incubating -public class OrdinalParameterDescriptor extends AbstractParameterDescriptor { +public class OrdinalParameterDescriptor extends AbstractParameterDescriptor { private final int label; private final int valuePosition; @@ -25,7 +25,7 @@ public class OrdinalParameterDescriptor extends AbstractParameterDescriptor { public OrdinalParameterDescriptor( int label, int valuePosition, - AllowableParameterType expectedType, + AllowableParameterType expectedType, int[] sourceLocations) { super( sourceLocations, expectedType ); this.label = label; 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 7b42b94b37..d3bbe74b63 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 @@ -39,7 +39,7 @@ import org.hibernate.internal.FastSessionServices; 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.query.AllowableParameterType; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.persister.collection.CollectionPersister; diff --git a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/PathQualifierType.java b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/PathQualifierType.java index 28fdba7cfa..79b5a9be0a 100644 --- a/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/PathQualifierType.java +++ b/hibernate-core/src/main/java/org/hibernate/graph/internal/parse/PathQualifierType.java @@ -7,6 +7,7 @@ package org.hibernate.graph.internal.parse; import org.hibernate.graph.CannotContainSubGraphException; +import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.metamodel.model.domain.ManagedDomainType; @@ -35,7 +36,7 @@ public enum PathQualifierType { ); private static ManagedDomainType resolveSubTypeManagedType( - SimpleDomainType graphType, + DomainType graphType, String subTypeName) { if ( !( graphType instanceof ManagedDomainType ) ) { throw new CannotContainSubGraphException( "The given type [" + graphType + "] is not a ManagedType" ); 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 41a7aef057..cdfa1c0712 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -99,7 +99,7 @@ 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.query.AllowableParameterType; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl; import org.hibernate.metamodel.spi.MetamodelImplementor; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/MappingMetamodel.java b/hibernate-core/src/main/java/org/hibernate/metamodel/MappingMetamodel.java index 72d78717c1..432126f930 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/MappingMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/MappingMetamodel.java @@ -13,7 +13,7 @@ import java.util.function.Function; import org.hibernate.Incubating; import org.hibernate.graph.RootGraph; import org.hibernate.metamodel.mapping.MappingModelExpressable; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.persister.collection.CollectionPersister; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java index c8a3c21ee3..bec8210494 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java @@ -31,6 +31,7 @@ import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.model.domain.AbstractIdentifiableType; +import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.IdentifiableDomainType; import org.hibernate.metamodel.model.domain.ManagedDomainType; @@ -110,15 +111,15 @@ public class AttributeFactory { normalMemberResolver, metadataContext ); - if ( attributeMetadata == null ) { - return null; - } - if ( attributeMetadata.isPlural() ) { + + if ( attributeMetadata instanceof PluralAttributeMetadata ) { + //noinspection rawtypes return PluralAttributeBuilder.build( (PluralAttributeMetadata) attributeMetadata, metadataContext ); } + final SingularAttributeMetadata singularAttributeMetadata = (SingularAttributeMetadata) attributeMetadata; - final SimpleDomainType metaModelType = determineSimpleType( singularAttributeMetadata.getValueContext(), metadataContext ); - return new SingularAttributeImpl( + final DomainType metaModelType = determineSimpleType( singularAttributeMetadata.getValueContext(), metadataContext ); + return new SingularAttributeImpl<>( ownerType, attributeMetadata.getName(), attributeMetadata.getAttributeClassification(), @@ -132,7 +133,7 @@ public class AttributeFactory { } private static AttributeContext wrap(final ManagedDomainType ownerType, final Property property) { - return new AttributeContext() { + return new AttributeContext<>() { public ManagedDomainType getOwnerType() { return ownerType; } @@ -153,7 +154,6 @@ public class AttributeFactory { * * @return The built attribute descriptor */ - @SuppressWarnings({"unchecked"}) public SingularPersistentAttribute buildIdAttribute( IdentifiableDomainType ownerType, Property property) { @@ -164,15 +164,15 @@ public class AttributeFactory { // id-attribute = "id" - final SingularAttributeMetadata attributeMetadata = (SingularAttributeMetadata) determineAttributeMetadata( + final SingularAttributeMetadata attributeMetadata = (SingularAttributeMetadata) determineAttributeMetadata( wrap( ownerType, property ), identifierMemberResolver ); - return new SingularAttributeImpl.Identifier( + return new SingularAttributeImpl.Identifier<>( ownerType, property.getName(), - determineSimpleType( attributeMetadata.getValueContext() ), + (SimpleDomainType) determineSimpleType( attributeMetadata.getValueContext() ), attributeMetadata.getMember(), attributeMetadata.getAttributeClassification(), context @@ -189,7 +189,6 @@ public class AttributeFactory { * * @return The built attribute descriptor */ - @SuppressWarnings({"unchecked"}) public SingularAttributeImpl buildVersionAttribute( IdentifiableDomainType ownerType, Property property) { @@ -200,22 +199,22 @@ public class AttributeFactory { versionMemberResolver ); - return new SingularAttributeImpl.Version( + return new SingularAttributeImpl.Version<>( ownerType, property.getName(), attributeMetadata.getAttributeClassification(), - determineSimpleType( attributeMetadata.getValueContext() ), + (SimpleDomainType) determineSimpleType( attributeMetadata.getValueContext() ), attributeMetadata.getMember(), context ); } - private SimpleDomainType determineSimpleType(ValueContext typeContext) { + private DomainType determineSimpleType(ValueContext typeContext) { return determineSimpleType( typeContext, context ); } @SuppressWarnings("unchecked") - public static SimpleDomainType determineSimpleType(ValueContext typeContext, MetadataContext context) { + public static DomainType determineSimpleType(ValueContext typeContext, MetadataContext context) { switch ( typeContext.getValueClassification() ) { case BASIC: { return context.resolveBasicType( typeContext.getJpaBindableType() ); @@ -229,7 +228,7 @@ public class AttributeFactory { assert type instanceof AnyType; final AnyType anyType = (AnyType) type; - final JavaType baseJtd = context.getTypeConfiguration() + final JavaType baseJtd = context.getTypeConfiguration() .getJavaTypeDescriptorRegistry() .resolveDescriptor( anyType.getReturnedClass() ); return new AnyMappingDomainTypeImpl<>( anyType, baseJtd ); @@ -239,7 +238,7 @@ public class AttributeFactory { final EmbeddableTypeImpl embeddableType; if ( component.isDynamic() ) { - final JavaType javaTypeDescriptor = context.getJavaTypeDescriptorRegistry().getDescriptor( java.util.Map.class ); + final JavaType javaTypeDescriptor = context.getJavaTypeDescriptorRegistry().getDescriptor( java.util.Map.class ); embeddableType = new EmbeddableTypeImpl<>( javaTypeDescriptor, @@ -293,10 +292,6 @@ public class AttributeFactory { } } - private EntityMetamodel getDeclarerEntityMetamodel(AbstractIdentifiableType ownerType) { - return getDeclarerEntityMetamodel( ownerType, context ); - } - private static EntityPersister getDeclaringEntity( AbstractIdentifiableType ownerType, MetadataContext metadataContext) { @@ -347,7 +342,6 @@ public class AttributeFactory { * * @return The attribute description */ - @SuppressWarnings({"unchecked"}) private AttributeMetadata determineAttributeMetadata( AttributeContext attributeContext, MemberResolver memberResolver) { @@ -447,7 +441,7 @@ public class AttributeFactory { else { indexClassification = null; } - return new PluralAttributeMetadataImpl( + return new PluralAttributeMetadataImpl<>( propertyMapping, attributeContext.getOwnerType(), member, @@ -644,7 +638,7 @@ public class AttributeFactory { * A {@link Member} resolver for normal attributes. */ private static final MemberResolver normalMemberResolver = (attributeContext, metadataContext) -> { - final ManagedDomainType ownerType = attributeContext.getOwnerType(); + final ManagedDomainType ownerType = attributeContext.getOwnerType(); final Property property = attributeContext.getPropertyMapping(); final Type.PersistenceType persistenceType = ownerType.getPersistenceType(); if ( Type.PersistenceType.EMBEDDABLE == persistenceType ) { @@ -652,7 +646,7 @@ public class AttributeFactory { } else if ( Type.PersistenceType.ENTITY == persistenceType || Type.PersistenceType.MAPPED_SUPERCLASS == persistenceType ) { - final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) ownerType; + final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) ownerType; final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext ); final EntityMetamodel entityMetamodel = declaringEntityMapping.getEntityMetamodel(); final String propertyName = property.getName(); @@ -674,7 +668,7 @@ public class AttributeFactory { }; private final MemberResolver identifierMemberResolver = (attributeContext, metadataContext) -> { - final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType(); + final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType(); final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext ); final EntityMetamodel entityMetamodel = declaringEntityMapping.getEntityMetamodel(); @@ -696,30 +690,25 @@ public class AttributeFactory { } }; - private final MemberResolver versionMemberResolver = new MemberResolver() { - @Override - public Member resolveMember( - AttributeContext attributeContext, - MetadataContext metadataContext) { - final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType(); - final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext ); - final EntityMetamodel entityMetamodel = declaringEntityMapping.getEntityMetamodel(); - final String versionPropertyName = attributeContext.getPropertyMapping().getName(); - if ( !versionPropertyName.equals( entityMetamodel.getVersionProperty().getName() ) ) { - // this should never happen, but to be safe... - throw new IllegalArgumentException( "Given property did not match declared version property" ); - } + private final MemberResolver versionMemberResolver = (attributeContext, metadataContext) -> { + final AbstractIdentifiableType identifiableType = (AbstractIdentifiableType) attributeContext.getOwnerType(); + final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext ); + final EntityMetamodel entityMetamodel = declaringEntityMapping.getEntityMetamodel(); + final String versionPropertyName = attributeContext.getPropertyMapping().getName(); + if ( !versionPropertyName.equals( entityMetamodel.getVersionProperty().getName() ) ) { + // this should never happen, but to be safe... + throw new IllegalArgumentException( "Given property did not match declared version property" ); + } - final Getter getter = declaringEntityMapping.getRepresentationStrategy().resolvePropertyAccess( attributeContext.getPropertyMapping() ).getGetter(); - if ( PropertyAccessMapImpl.GetterImpl.class.isInstance( getter ) ) { - return new MapMember( - versionPropertyName, - attributeContext.getPropertyMapping().getType().getReturnedClass() - ); - } - else { - return getter.getMember(); - } + final Getter getter = declaringEntityMapping.getRepresentationStrategy().resolvePropertyAccess( attributeContext.getPropertyMapping() ).getGetter(); + if ( getter instanceof PropertyAccessMapImpl.GetterImpl ) { + return new MapMember( + versionPropertyName, + attributeContext.getPropertyMapping().getType().getReturnedClass() + ); + } + else { + return getter.getMember(); } }; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PluralAttributeMetadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PluralAttributeMetadata.java index af9c71dfb4..30aabcb4ac 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PluralAttributeMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/PluralAttributeMetadata.java @@ -11,12 +11,12 @@ import org.hibernate.metamodel.CollectionClassification; /** * Attribute metadata contract for a plural attribute. * - * @param The owner type - * @param The attribute type (the collection type) + * @param The owner type + * @param The attribute type (the collection type) * @param The collection element type */ @SuppressWarnings("UnusedDeclaration") -public interface PluralAttributeMetadata extends AttributeMetadata { +public interface PluralAttributeMetadata extends AttributeMetadata { /** * The classification of the collection, indicating the collection semantics * to be used. diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractDomainType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractDomainType.java index 02587e74c8..817ade5359 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractDomainType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractDomainType.java @@ -34,4 +34,9 @@ public abstract class AbstractDomainType implements SimpleDomainType { public Class getJavaType() { return getExpressableJavaTypeDescriptor().getJavaTypeClass(); } + + @Override + public Class getBindableJavaType() { + return getJavaType(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableParameterType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableParameterType.java deleted file mode 100644 index fa27d80672..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableParameterType.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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.model.domain; - -import org.hibernate.Incubating; -import org.hibernate.query.Query; -import org.hibernate.type.descriptor.java.JavaType; - -/** - * Specialization of {@link DomainType} for types that can be used as {@link Query} parameter bind values. - * - * @author Steve Ebersole - */ -@Incubating -public interface AllowableParameterType extends SimpleDomainType { - JavaType getExpressableJavaTypeDescriptor(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/BasicDomainType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/BasicDomainType.java index 0f42e55077..ba685caab0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/BasicDomainType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/BasicDomainType.java @@ -10,6 +10,8 @@ import java.util.Objects; import jakarta.persistence.metamodel.BasicType; import org.hibernate.HibernateException; +import org.hibernate.query.AllowableFunctionReturnType; +import org.hibernate.query.AllowableOutputParameterType; import org.hibernate.query.sqm.SqmExpressable; /** diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/EmbeddableDomainType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/EmbeddableDomainType.java index 03bb8969dd..d72b8780c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/EmbeddableDomainType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/EmbeddableDomainType.java @@ -6,7 +6,8 @@ */ package org.hibernate.metamodel.model.domain; -import org.hibernate.metamodel.ManagedTypeRepresentationStrategy; +import org.hibernate.query.AllowableParameterType; +import org.hibernate.query.sqm.SqmExpressable; import jakarta.persistence.metamodel.EmbeddableType; @@ -18,5 +19,6 @@ import jakarta.persistence.metamodel.EmbeddableType; * * @author Steve Ebersole */ -public interface EmbeddableDomainType extends ManagedDomainType, EmbeddableType, AllowableParameterType { +public interface EmbeddableDomainType + extends ManagedDomainType, EmbeddableType, AllowableParameterType, SqmExpressable { } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/ManagedDomainType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/ManagedDomainType.java index 5751f869e7..34dac70fe9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/ManagedDomainType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/ManagedDomainType.java @@ -7,17 +7,19 @@ package org.hibernate.metamodel.model.domain; import java.util.function.Consumer; -import jakarta.persistence.metamodel.ManagedType; import org.hibernate.graph.spi.SubGraphImplementor; import org.hibernate.metamodel.RepresentationMode; +import org.hibernate.query.sqm.SqmExpressable; + +import jakarta.persistence.metamodel.ManagedType; /** * Hibernate extension to the JPA {@link ManagedType} contract * * @author Steve Ebersole */ -public interface ManagedDomainType extends AllowableParameterType, ManagedType { +public interface ManagedDomainType extends SqmExpressable, DomainType, ManagedType { /** * Get the type name. * diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PersistentAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PersistentAttribute.java index 73d1c806d9..83b51408d4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PersistentAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PersistentAttribute.java @@ -27,6 +27,6 @@ public interface PersistentAttribute extends Attribute { */ AttributeClassification getAttributeClassification(); - SimpleDomainType getValueGraphType(); + DomainType getValueGraphType(); SimpleDomainType getKeyGraphType(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PluralPersistentAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PluralPersistentAttribute.java index 0bd157516f..ddfacb9df5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PluralPersistentAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PluralPersistentAttribute.java @@ -22,7 +22,7 @@ import org.hibernate.query.sqm.SqmPathSource; * @author Steve Ebersole */ public interface PluralPersistentAttribute - extends PersistentAttribute, SqmPathSource, SqmJoinable, PluralAttribute { + extends PersistentAttribute, SqmPathSource, SqmJoinable, PluralAttribute { @Override ManagedDomainType getDeclaringType(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SimpleDomainType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SimpleDomainType.java index 1b23e35fe7..5b565b830c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SimpleDomainType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SimpleDomainType.java @@ -12,4 +12,8 @@ package org.hibernate.metamodel.model.domain; * @author Steve Ebersole */ public interface SimpleDomainType extends DomainType, jakarta.persistence.metamodel.Type { + @Override + default Class getBindableJavaType() { + return getJavaType(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SingularPersistentAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SingularPersistentAttribute.java index b839ce6f07..4bdb99a31d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SingularPersistentAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SingularPersistentAttribute.java @@ -25,14 +25,14 @@ public interface SingularPersistentAttribute ManagedDomainType getDeclaringType(); @Override - SimpleDomainType getSqmPathType(); + DomainType getSqmPathType(); /** * For a singular attribute, the value type is defined as the * attribute type */ @Override - default SimpleDomainType getValueGraphType() { + default DomainType getValueGraphType() { return getType(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractAttribute.java index d8cc5ffcce..fcefd2e1f1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractAttribute.java @@ -14,6 +14,7 @@ import jakarta.persistence.metamodel.Attribute; import org.hibernate.metamodel.AttributeClassification; import org.hibernate.metamodel.internal.MetadataContext; +import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.PersistentAttribute; import org.hibernate.metamodel.model.domain.SimpleDomainType; @@ -34,7 +35,7 @@ public abstract class AbstractAttribute implements PersistentAttribute valueType; + private final DomainType valueType; private transient Member member; @SuppressWarnings("WeakerAccess") @@ -43,7 +44,7 @@ public abstract class AbstractAttribute implements PersistentAttribute attributeJtd, AttributeClassification attributeClassification, - SimpleDomainType valueType, + DomainType valueType, Member member, MetadataContext metadataContext) { this.declaringType = declaringType; @@ -64,7 +65,7 @@ public abstract class AbstractAttribute implements PersistentAttribute getSqmPathType() { + public DomainType getSqmPathType() { return valueType; } @@ -94,7 +95,7 @@ public abstract class AbstractAttribute implements PersistentAttribute getValueGraphType() { + public DomainType getValueGraphType() { return valueType; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java index e52d626726..65c0e693cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java @@ -27,6 +27,11 @@ public abstract class AbstractSqmPathSource implements SqmPathSource { this.jpaBindableType = jpaBindableType; } + @Override + public Class getBindableJavaType() { + return domainType.getBindableJavaType(); + } + @Override public String getPathName() { return localPathName; @@ -46,9 +51,4 @@ public abstract class AbstractSqmPathSource implements SqmPathSource { public JavaType getExpressableJavaTypeDescriptor() { return domainType.getExpressableJavaTypeDescriptor(); } - - @Override - public Class getBindableJavaType() { - return getExpressableJavaTypeDescriptor().getJavaTypeClass(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingDomainTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingDomainTypeImpl.java index db70c7601e..cd4abb7792 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingDomainTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingDomainTypeImpl.java @@ -19,7 +19,7 @@ public class AnyMappingDomainTypeImpl implements AnyMappingDomainType { private final AnyType anyType; private final JavaType baseJtd; - public AnyMappingDomainTypeImpl(AnyType anyType, JavaType baseJtd) { + public AnyMappingDomainTypeImpl(AnyType anyType, JavaType baseJtd) { this.anyType = anyType; this.baseJtd = baseJtd; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java index bd97974488..5e3b4bcfaf 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java @@ -6,7 +6,7 @@ */ package org.hibernate.metamodel.model.domain.internal; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.metamodel.UnsupportedMappingException; import org.hibernate.metamodel.model.domain.AnyMappingDomainType; import org.hibernate.metamodel.model.domain.BasicDomainType; @@ -58,15 +58,4 @@ public class AnyMappingSqmPathSource extends AbstractSqmPathSource impleme } return new SqmAnyValuedSimplePath<>( navigablePath, this, lhs, lhs.nodeBuilder() ); } - - @Override - public PersistenceType getPersistenceType() { - // todo (6.0): no idea what is best here - return PersistenceType.EMBEDDABLE; - } - - @Override - public Class getJavaType() { - return getBindableJavaType(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ArrayTupleType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ArrayTupleType.java index 3c9a84bf90..d8b9460fee 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ArrayTupleType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ArrayTupleType.java @@ -15,9 +15,9 @@ import org.hibernate.mapping.IndexedConsumer; import org.hibernate.metamodel.UnsupportedMappingException; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.MappingModelExpressable; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.metamodel.model.domain.TupleType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.sql.ast.Clause; import org.hibernate.type.descriptor.java.JavaType; @@ -26,8 +26,10 @@ import org.hibernate.type.descriptor.java.ObjectArrayJavaTypeDescriptor; /** * @author Christian Beikov */ -public class ArrayTupleType implements TupleType, AllowableParameterType, AllowableFunctionReturnType, - MappingModelExpressable { +public class ArrayTupleType implements TupleType, + AllowableParameterType, + AllowableFunctionReturnType, + MappingModelExpressable { private final ObjectArrayJavaTypeDescriptor javaTypeDescriptor; private final SqmExpressable[] components; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java index 4264f5cc8f..c8f6829fb2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java @@ -6,9 +6,9 @@ */ package org.hibernate.metamodel.model.domain.internal; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.BasicDomainType; +import org.hibernate.query.AllowableFunctionReturnType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.NavigablePath; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicTypeImpl.java index 57a19f6050..8f296468fd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicTypeImpl.java @@ -61,6 +61,4 @@ public class BasicTypeImpl implements BasicDomainType, Serializable { throws SQLException { throw new NotYetImplementedFor6Exception( getClass() ); } - - } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DiscriminatorSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DiscriminatorSqmPathSource.java index 203ad67408..0b0f59b210 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DiscriminatorSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DiscriminatorSqmPathSource.java @@ -8,10 +8,10 @@ package org.hibernate.metamodel.model.domain.internal; import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping; import org.hibernate.metamodel.mapping.EntityMappingType; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; +import org.hibernate.query.AllowableFunctionReturnType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.NavigablePath; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.tree.domain.SqmPath; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddableTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddableTypeImpl.java index 772da1aaad..f776a8e247 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddableTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddableTypeImpl.java @@ -10,10 +10,10 @@ import java.io.Serializable; import org.hibernate.graph.internal.SubGraphImpl; import org.hibernate.graph.spi.SubGraphImplementor; -import org.hibernate.metamodel.ManagedTypeRepresentationStrategy; import org.hibernate.metamodel.model.domain.AbstractManagedType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; +import org.hibernate.query.AllowableParameterType; import org.hibernate.type.descriptor.java.JavaType; /** @@ -25,7 +25,7 @@ import org.hibernate.type.descriptor.java.JavaType; */ public class EmbeddableTypeImpl extends AbstractManagedType - implements EmbeddableDomainType, Serializable { + implements EmbeddableDomainType, AllowableParameterType, Serializable { private final boolean isDynamic; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java index 864340b8d8..c142078465 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java @@ -6,7 +6,7 @@ */ package org.hibernate.metamodel.model.domain.internal; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.query.NavigablePath; import org.hibernate.query.sqm.SqmPathSource; @@ -33,16 +33,6 @@ public class EmbeddedSqmPathSource return (EmbeddableDomainType) super.getSqmPathType(); } - @Override - public PersistenceType getPersistenceType() { - return PersistenceType.EMBEDDABLE; - } - - @Override - public Class getJavaType() { - return getBindableJavaType(); - } - @Override public SqmPathSource findSubPathSource(String name) { return (SqmPathSource) getSqmPathType().findAttribute( name ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java index a8e86bc65a..4b70f0e537 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java @@ -15,8 +15,6 @@ import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmPluralPartJoin; -import org.hibernate.query.sqm.tree.domain.SqmSingularJoin; -import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmFrom; /** diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java index 6f7390e427..df0b868327 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java @@ -145,11 +145,6 @@ public class EntityTypeImpl return BindableType.ENTITY_TYPE; } - @Override - public Class getBindableJavaType() { - return getJavaType(); - } - @Override public PersistenceType getPersistenceType() { return PersistenceType.ENTITY; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java index c6f88d433c..ffd60593c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java @@ -51,7 +51,7 @@ import org.hibernate.metamodel.internal.JpaMetaModelPopulationSetting; 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.query.AllowableParameterType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java index 605c5f1f63..324406d735 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/PluralAttributeBuilder.java @@ -19,6 +19,7 @@ import org.hibernate.metamodel.UnsupportedMappingException; import org.hibernate.metamodel.internal.AttributeFactory; import org.hibernate.metamodel.internal.MetadataContext; import org.hibernate.metamodel.internal.PluralAttributeMetadata; +import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.PersistentAttribute; import org.hibernate.metamodel.model.domain.SimpleDomainType; @@ -35,8 +36,8 @@ public class PluralAttributeBuilder { private final AttributeClassification attributeClassification; private final CollectionClassification collectionClassification; - private final SimpleDomainType elementType; - private final SimpleDomainType listIndexOrMapKeyType; + private final DomainType elementType; + private final DomainType listIndexOrMapKeyType; private final ManagedDomainType declaringType; @@ -47,8 +48,8 @@ public class PluralAttributeBuilder { JavaType collectionJtd, AttributeClassification attributeClassification, CollectionClassification collectionClassification, - SimpleDomainType elementType, - SimpleDomainType listIndexOrMapKeyType, + DomainType elementType, + DomainType listIndexOrMapKeyType, ManagedDomainType declaringType, Property property, Member member) { @@ -62,6 +63,7 @@ public class PluralAttributeBuilder { this.member = member; } + @SuppressWarnings({ "unchecked", "rawtypes" }) public static PersistentAttribute build( PluralAttributeMetadata attributeMetadata, MetadataContext metadataContext) { @@ -70,7 +72,6 @@ public class PluralAttributeBuilder { .getJavaTypeDescriptorRegistry() .getDescriptor( attributeMetadata.getJavaType() ); - //noinspection unchecked final PluralAttributeBuilder builder = new PluralAttributeBuilder( attributeJtd, attributeMetadata.getAttributeClassification(), @@ -86,43 +87,34 @@ public class PluralAttributeBuilder { ); if ( Map.class.equals( attributeJtd.getJavaTypeClass() ) ) { - //noinspection unchecked - return new MapAttributeImpl<>( builder, metadataContext ); + return new MapAttributeImpl( builder, metadataContext ); } else if ( Set.class.equals( attributeJtd.getJavaTypeClass() ) ) { - //noinspection unchecked - return new SetAttributeImpl<>( builder, metadataContext ); + return new SetAttributeImpl( builder, metadataContext ); } else if ( List.class.equals( attributeJtd.getJavaTypeClass() ) ) { - //noinspection unchecked - return new ListAttributeImpl<>( builder, metadataContext ); + return new ListAttributeImpl( builder, metadataContext ); } else if ( Collection.class.equals( attributeJtd.getJavaTypeClass() ) ) { - //noinspection unchecked - return new BagAttributeImpl<>( builder, metadataContext ); + return new BagAttributeImpl( builder, metadataContext ); } //apply loose rules if ( attributeJtd.getJavaTypeClass().isArray() ) { - //noinspection unchecked - return new ListAttributeImpl<>( builder, metadataContext ); + return new ListAttributeImpl( builder, metadataContext ); } if ( Map.class.isAssignableFrom( attributeJtd.getJavaTypeClass() ) ) { - //noinspection unchecked - return new MapAttributeImpl<>( builder, metadataContext ); + return new MapAttributeImpl( builder, metadataContext ); } else if ( Set.class.isAssignableFrom( attributeJtd.getJavaTypeClass() ) ) { - //noinspection unchecked - return new SetAttributeImpl<>( builder, metadataContext ); + return new SetAttributeImpl( builder, metadataContext ); } else if ( List.class.isAssignableFrom( attributeJtd.getJavaTypeClass() ) ) { - //noinspection unchecked - return new ListAttributeImpl<>( builder, metadataContext ); + return new ListAttributeImpl( builder, metadataContext ); } else if ( Collection.class.isAssignableFrom( attributeJtd.getJavaTypeClass() ) ) { - //noinspection unchecked - return new BagAttributeImpl<>( builder, metadataContext ); + return new BagAttributeImpl( builder, metadataContext ); } throw new UnsupportedMappingException( "Unknown collection: " + attributeJtd.getJavaType() ); @@ -132,7 +124,7 @@ public class PluralAttributeBuilder { PluralAttributeMetadata attributeMetadata, MetadataContext metadataContext) { if ( Map.class.isAssignableFrom( attributeMetadata.getJavaType() ) ) { - return determineSimpleType( attributeMetadata.getMapKeyValueContext(), metadataContext ); + return (SimpleDomainType) determineSimpleType( attributeMetadata.getMapKeyValueContext(), metadataContext ); } if ( List.class.isAssignableFrom( attributeMetadata.getJavaType() ) @@ -155,7 +147,7 @@ public class PluralAttributeBuilder { return collectionClassification; } - public SimpleDomainType getListIndexOrMapKeyType() { + public DomainType getListIndexOrMapKeyType() { return listIndexOrMapKeyType; } @@ -163,7 +155,7 @@ public class PluralAttributeBuilder { return collectionJtd; } - public SimpleDomainType getValueType() { + public DomainType getValueType() { return elementType; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java index f2f98dcd46..34477d7cbb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java @@ -14,6 +14,7 @@ import org.hibernate.graph.spi.GraphHelper; import org.hibernate.metamodel.AttributeClassification; import org.hibernate.metamodel.internal.MetadataContext; import org.hibernate.metamodel.model.domain.AnyMappingDomainType; +import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.metamodel.model.domain.SingularPersistentAttribute; @@ -48,7 +49,7 @@ public class SingularAttributeImpl ManagedDomainType declaringType, String name, AttributeClassification attributeClassification, - SimpleDomainType attributeType, + DomainType attributeType, Member member, boolean isIdentifier, boolean isVersion, diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/FunctionReturnImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/FunctionReturnImpl.java index ac59ee47d7..70ffa3926e 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/FunctionReturnImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/FunctionReturnImpl.java @@ -11,8 +11,8 @@ import java.sql.Types; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.metamodel.model.domain.AllowableOutputParameterType; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableOutputParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.procedure.spi.FunctionReturnImplementor; import org.hibernate.procedure.spi.NamedCallableQueryMemento; import org.hibernate.procedure.spi.ProcedureCallImplementor; diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java index 05258d86ca..825560ca47 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java @@ -14,7 +14,7 @@ import jakarta.persistence.ParameterMode; import org.hibernate.CacheMode; import org.hibernate.FlushMode; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.procedure.ProcedureCall; import org.hibernate.procedure.spi.NamedCallableQueryMemento; import org.hibernate.procedure.spi.ParameterStrategy; diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java index cc1864baaf..aae77badd6 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java @@ -33,7 +33,6 @@ import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.mapping.JdbcMapping; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.procedure.NoSuchParameterException; import org.hibernate.procedure.ParameterStrategyException; @@ -45,6 +44,7 @@ import org.hibernate.procedure.spi.NamedCallableQueryMemento; import org.hibernate.procedure.spi.ParameterStrategy; import org.hibernate.procedure.spi.ProcedureCallImplementor; import org.hibernate.procedure.spi.ProcedureParameterImplementor; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.Query; import org.hibernate.query.QueryParameter; import org.hibernate.query.internal.QueryOptionsImpl; @@ -60,6 +60,7 @@ import org.hibernate.query.spi.QueryOptionsAdapter; import org.hibernate.query.spi.QueryParameterBinding; import org.hibernate.query.spi.QueryParameterBindings; import org.hibernate.query.spi.ScrollableResultsImplementor; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.result.NoMoreReturnsException; import org.hibernate.result.Output; import org.hibernate.result.ResultSetOutput; @@ -146,7 +147,7 @@ public class ProcedureCallImpl * @param procedureName The name of the procedure to call * @param resultClasses The classes making up the result */ - public ProcedureCallImpl(SharedSessionContractImplementor session, String procedureName, Class... resultClasses) { + public ProcedureCallImpl(SharedSessionContractImplementor session, String procedureName, Class... resultClasses) { super( session ); assert resultClasses != null && resultClasses.length > 0; @@ -455,16 +456,29 @@ public class ProcedureCallImpl @Override public ProcedureParameter registerParameter(int position, Class javaType, ParameterMode mode) { - final AllowableParameterType parameterType = getSessionFactory().getDomainModel().resolveQueryParameterType( - javaType - ); + final AllowableParameterType parameterType = getSessionFactory() + .getDomainModel() + .resolveQueryParameterType( javaType ); + + final Class expressableJavaType; + if ( parameterType == null ) { + expressableJavaType = null; + } + else { + final SqmExpressable sqmExpressable = parameterType.resolveExpressable( getSessionFactory() ); + assert sqmExpressable != null; + + expressableJavaType = sqmExpressable.getExpressableJavaTypeDescriptor().getJavaTypeClass(); + } + final ProcedureParameterImpl procedureParameter = new ProcedureParameterImpl<>( position, mode, - parameterType == null ? javaType : parameterType.getJavaType(), + expressableJavaType, parameterType ); registerParameter( procedureParameter ); + return procedureParameter; } @@ -486,25 +500,24 @@ public class ProcedureCallImpl return procedureParameter; } - private void registerParameter(ProcedureParameterImplementor parameter) { + private void registerParameter(ProcedureParameterImplementor parameter) { getParameterMetadata().registerParameter( parameter ); } @Override - public ProcedureParameterImplementor getParameterRegistration(int position) { + public ProcedureParameterImplementor getParameterRegistration(int position) { return getParameterMetadata().getQueryParameter( position ); } @Override - @SuppressWarnings("unchecked") public ProcedureParameterImplementor registerParameter(String name, Class javaType, ParameterMode mode) { final AllowableParameterType parameterType = getSessionFactory().getDomainModel().resolveQueryParameterType( javaType ); - final ProcedureParameterImpl parameter = new ProcedureParameterImpl( + final ProcedureParameterImpl parameter = new ProcedureParameterImpl<>( name, mode, - parameterType.getJavaType(), + parameterType.getBindableJavaType(), parameterType ); @@ -514,7 +527,6 @@ public class ProcedureCallImpl } @Override - @SuppressWarnings("unchecked") public ProcedureParameterImplementor registerParameter( String name, BasicTypeReference typeReference, @@ -522,7 +534,7 @@ public class ProcedureCallImpl final BasicType basicType = getSessionFactory().getTypeConfiguration() .getBasicTypeRegistry() .resolve( typeReference ); - final ProcedureParameterImpl parameter = new ProcedureParameterImpl( + final ProcedureParameterImpl parameter = new ProcedureParameterImpl<>( name, mode, basicType.getJavaType(), @@ -535,12 +547,12 @@ public class ProcedureCallImpl } @Override - public ProcedureParameterImplementor getParameterRegistration(String name) { + public ProcedureParameterImplementor getParameterRegistration(String name) { return getParameterMetadata().getQueryParameter( name ); } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) public List getRegisteredParameters() { return getParameterMetadata().getRegistrationsAsList() ; } @@ -784,7 +796,7 @@ public class ProcedureCallImpl parameterMetadata.visitRegistrations( queryParameter -> { - final ProcedureParameterImplementor procedureParameter = (ProcedureParameterImplementor) queryParameter; + final ProcedureParameterImplementor procedureParameter = (ProcedureParameterImplementor) queryParameter; mementos.add( new NamedCallableQueryMementoImpl.ParameterMementoImpl( procedureParameter.getPosition(), @@ -1114,50 +1126,6 @@ public class ProcedureCallImpl return this; } - @Override - public

ProcedureCallImplementor setParameter(String name, P value, BasicTypeReference

type) { - super.setParameter( name, value, type ); - return this; - } - - @Override - public

ProcedureCallImplementor setParameter(int position, P value, BasicTypeReference

type) { - super.setParameter( position, value, type ); - return this; - } - - @Override - public

ProcedureCallImplementor setParameter(QueryParameter

parameter, P val, BasicTypeReference

type) { - super.setParameter( parameter, val, type ); - return this; - } -// @Override -// public ProcedureCallImplementor setParameter(int position, Object value, Type type) { -// super.setParameter( position, value, type ); -// return this; -// } - - @Override - public

ProcedureCallImplementor setParameter( - QueryParameter

parameter, - P value, - TemporalType temporalPrecision) { - super.setParameter( parameter, value, temporalPrecision ); - return this; - } - - @Override - public ProcedureCallImplementor setParameter(String name, Object value, TemporalType temporalPrecision) { - super.setParameter( name, value, temporalPrecision ); - return this; - } - - @Override - public ProcedureCallImplementor setParameter(int position, Object value, TemporalType temporalPrecision) { - super.setParameter( position, value, temporalPrecision ); - return this; - } - @Override public ProcedureCallImplementor setParameter( Parameter parameter, @@ -1198,8 +1166,7 @@ public class ProcedureCallImpl } @Override - @SuppressWarnings("unchecked") - public Stream getResultStream() { + public Stream getResultStream() { return getResultList().stream(); } diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParamBindings.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParamBindings.java index 1648996ae7..6ef74f2165 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParamBindings.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParamBindings.java @@ -12,12 +12,12 @@ import java.util.function.BiConsumer; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.cache.spi.QueryKey; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.procedure.spi.ProcedureParameterBindingImplementor; import org.hibernate.procedure.spi.ProcedureParameterImplementor; import org.hibernate.query.procedure.ProcedureParameterBinding; import org.hibernate.query.spi.QueryParameterBinding; -import org.hibernate.query.spi.QueryParameterBindingTypeResolver; import org.hibernate.query.spi.QueryParameterBindings; import org.hibernate.query.spi.QueryParameterImplementor; @@ -26,15 +26,15 @@ import org.hibernate.query.spi.QueryParameterImplementor; */ public class ProcedureParamBindings implements QueryParameterBindings { private final ProcedureParameterMetadataImpl parameterMetadata; - private final QueryParameterBindingTypeResolver typeResolver; + private final SessionFactoryImplementor sessionFactory; private final Map, ProcedureParameterBindingImplementor> bindingMap = new HashMap<>(); public ProcedureParamBindings( ProcedureParameterMetadataImpl parameterMetadata, - QueryParameterBindingTypeResolver typeResolver) { + SessionFactoryImplementor sessionFactory) { this.parameterMetadata = parameterMetadata; - this.typeResolver = typeResolver; + this.sessionFactory = sessionFactory; } public ProcedureParameterMetadataImpl getParameterMetadata() { @@ -61,7 +61,7 @@ public class ProcedureParamBindings implements QueryParameterBindings { throw new IllegalArgumentException( "Passed parameter is not registered with this query" ); } - binding = new ProcedureParameterBindingImpl<>( procParam, typeResolver ); + binding = new ProcedureParameterBindingImpl<>( procParam, sessionFactory ); bindingMap.put( procParam, binding ); } diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParameterBindingImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParameterBindingImpl.java index 38c3336792..3693e33e98 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParameterBindingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParameterBindingImpl.java @@ -6,12 +6,11 @@ */ package org.hibernate.procedure.internal; -import org.hibernate.metamodel.model.domain.AllowableParameterType; -import org.hibernate.query.internal.QueryParameterBindingImpl; -import org.hibernate.query.procedure.ProcedureParameterBinding; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.procedure.spi.ProcedureParameterBindingImplementor; import org.hibernate.procedure.spi.ProcedureParameterImplementor; -import org.hibernate.query.spi.QueryParameterBindingTypeResolver; +import org.hibernate.query.internal.QueryParameterBindingImpl; +import org.hibernate.query.procedure.ProcedureParameterBinding; /** * Implementation of the {@link ProcedureParameterBinding} contract. @@ -23,14 +22,7 @@ public class ProcedureParameterBindingImpl implements ProcedureParameterBindingImplementor { public ProcedureParameterBindingImpl( ProcedureParameterImplementor queryParameter, - QueryParameterBindingTypeResolver typeResolver) { - super( queryParameter, typeResolver, true ); - } - - public ProcedureParameterBindingImpl( - AllowableParameterType bindType, - ProcedureParameterImplementor queryParameter, - QueryParameterBindingTypeResolver typeResolver) { - super( queryParameter, typeResolver, bindType, true ); + SessionFactoryImplementor sessionFactory) { + super( queryParameter, sessionFactory, true ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParameterImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParameterImpl.java index ec187a1829..9f07dbba0f 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParameterImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureParameterImpl.java @@ -15,12 +15,12 @@ import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.metamodel.mapping.JdbcMapping; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.procedure.spi.NamedCallableQueryMemento; import org.hibernate.procedure.spi.ParameterStrategy; import org.hibernate.procedure.spi.ProcedureCallImplementor; import org.hibernate.procedure.spi.ProcedureParameterImplementor; import org.hibernate.query.AbstractQueryParameter; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.internal.BindingTypeHelper; import org.hibernate.query.spi.QueryParameterBinding; import org.hibernate.sql.exec.internal.JdbcCallParameterExtractorImpl; @@ -30,10 +30,8 @@ import org.hibernate.sql.exec.internal.JdbcParameterImpl; import org.hibernate.sql.exec.spi.ExecutionContext; import org.hibernate.sql.exec.spi.JdbcCallParameterRegistration; import org.hibernate.sql.exec.spi.JdbcParameterBinder; -import org.hibernate.sql.exec.spi.JdbcParameterBindings; import org.hibernate.type.BasicType; import org.hibernate.type.ProcedureParameterNamedBinder; -import org.hibernate.type.spi.TypeConfiguration; import jakarta.persistence.ParameterMode; @@ -118,13 +116,12 @@ public class ProcedureParameterImpl extends AbstractQueryParameter impleme int startIndex, ProcedureCallImplementor procedureCall) { final QueryParameterBinding binding = procedureCall.getParameterBindings().getBinding( this ); - final TypeConfiguration typeConfiguration = procedureCall.getSession().getFactory().getTypeConfiguration(); final AllowableParameterType typeToUse = BindingTypeHelper.INSTANCE.resolveTemporalPrecision( binding == null || binding.getExplicitTemporalPrecision() == null ? null : binding.getExplicitTemporalPrecision(), getHibernateType(), - typeConfiguration + procedureCall.getSession().getFactory() ); final String name; diff --git a/hibernate-core/src/main/java/org/hibernate/query/AbstractQueryParameter.java b/hibernate-core/src/main/java/org/hibernate/query/AbstractQueryParameter.java index 74c454652b..b946cda3ed 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/AbstractQueryParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/AbstractQueryParameter.java @@ -6,7 +6,6 @@ */ package org.hibernate.query; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.query.spi.QueryParameterImplementor; /** @@ -57,6 +56,6 @@ public abstract class AbstractQueryParameter implements QueryParameterImpleme @Override public Class getParameterType() { - return anticipatedType.getJavaType(); + return anticipatedType.getBindableJavaType(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableFunctionReturnType.java b/hibernate-core/src/main/java/org/hibernate/query/AllowableFunctionReturnType.java similarity index 82% rename from hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableFunctionReturnType.java rename to hibernate-core/src/main/java/org/hibernate/query/AllowableFunctionReturnType.java index f9751df13e..2eaf901d94 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableFunctionReturnType.java +++ b/hibernate-core/src/main/java/org/hibernate/query/AllowableFunctionReturnType.java @@ -4,7 +4,9 @@ * 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.model.domain; +package org.hibernate.query; + +import org.hibernate.metamodel.model.domain.SimpleDomainType; /** * Specialization of DomainType for types that can be used as function returns diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableOutputParameterType.java b/hibernate-core/src/main/java/org/hibernate/query/AllowableOutputParameterType.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableOutputParameterType.java rename to hibernate-core/src/main/java/org/hibernate/query/AllowableOutputParameterType.java index 176f4927e6..754350cd41 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AllowableOutputParameterType.java +++ b/hibernate-core/src/main/java/org/hibernate/query/AllowableOutputParameterType.java @@ -4,12 +4,13 @@ * 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.model.domain; +package org.hibernate.query; import java.sql.CallableStatement; import java.sql.SQLException; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.query.AllowableParameterType; import org.hibernate.type.descriptor.jdbc.JdbcType; /** diff --git a/hibernate-core/src/main/java/org/hibernate/query/AllowableParameterType.java b/hibernate-core/src/main/java/org/hibernate/query/AllowableParameterType.java new file mode 100644 index 0000000000..1d9503180a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/AllowableParameterType.java @@ -0,0 +1,62 @@ +/* + * 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.query; + +import org.hibernate.Incubating; +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.query.sqm.SqmExpressable; + +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.metamodel.ManagedType; + +/** + * Types that can be used to handle binding {@link org.hibernate.query.Query} parameters + * + * @see org.hibernate.type.BasicTypeReference + * @see org.hibernate.type.StandardBasicTypes + * + * @author Steve Ebersole + */ +@Incubating +public interface AllowableParameterType { + /** + * The expected Java type + */ + Class getBindableJavaType(); + + static AllowableParameterType parameterType(Class type) { + throw new NotYetImplementedFor6Exception( "AllowableParameterType#parameterType" ); + } + + static AllowableParameterType parameterType(Class javaType, AttributeConverter converter) { + throw new NotYetImplementedFor6Exception( "AllowableParameterType#parameterType" ); + } + + static AllowableParameterType parameterType(Class javaType, Class> converter) { + throw new NotYetImplementedFor6Exception( "AllowableParameterType#parameterType" ); + } + + static AllowableParameterType parameterType(ManagedType managedType) { + throw new NotYetImplementedFor6Exception( "AllowableParameterType#parameterType" ); + } + + static AllowableParameterType parameterType(jakarta.persistence.metamodel.Bindable jpaBindable) { + throw new NotYetImplementedFor6Exception( "AllowableParameterType#parameterType" ); + } + + static AllowableParameterType parameterType(org.hibernate.metamodel.mapping.Bindable bindable) { + throw new NotYetImplementedFor6Exception( "AllowableParameterType#parameterType" ); + } + + /** + * Resolve this parameter type to the corresponding SqmExpressable + * + * @todo (6.0) - use SessionFactory (API) here instead - we'll just cast "below" + */ + SqmExpressable resolveExpressable(SessionFactoryImplementor sessionFactory); +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java b/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java index 4ce1a7deac..b55a2de483 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/NativeQuery.java @@ -28,7 +28,6 @@ import org.hibernate.LockOptions; import org.hibernate.MappingException; import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.PluralAttributeMapping; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.transform.ResultTransformer; import org.hibernate.type.BasicTypeReference; @@ -570,161 +569,114 @@ public interface NativeQuery extends Query, SynchronizeableQuery { @Override @SuppressWarnings("deprecation") NativeQuery setResultTransformer(ResultTransformer transformer); - @Override NativeQuery setParameter(String name, Object value); @Override - NativeQuery setParameter(int position, Object value); - - @Override -

NativeQuery setParameter(QueryParameter

parameter, P val); - - @Override - NativeQuery setParameter(Parameter param, Instant value, TemporalType temporalType); - - @Override - NativeQuery setParameter(Parameter param, LocalDateTime value, TemporalType temporalType); - - @Override - NativeQuery setParameter(Parameter param, ZonedDateTime value, TemporalType temporalType); - - @Override - NativeQuery setParameter(Parameter param, OffsetDateTime value, TemporalType temporalType); - - @Override - NativeQuery setParameter(String name, Instant value, TemporalType temporalType); - - @Override - NativeQuery setParameter(String name, LocalDateTime value, TemporalType temporalType); - - @Override - NativeQuery setParameter(String name, ZonedDateTime value, TemporalType temporalType); - - @Override - NativeQuery setParameter(String name, OffsetDateTime value, TemporalType temporalType); - - @Override - NativeQuery setParameter(int position, Instant value, TemporalType temporalType); - - @Override - NativeQuery setParameter(int position, LocalDateTime value, TemporalType temporalType); - - @Override - NativeQuery setParameter(int position, ZonedDateTime value, TemporalType temporalType); - - @Override - NativeQuery setParameter(int position, OffsetDateTime value, TemporalType temporalType); - - @Override -

NativeQuery setParameter(Parameter

param, P value); - - -// @Override -// NativeQuery setParameter(String name, Object val, Type type); -// -// @Override -// NativeQuery setParameter(int position, Object val, Type type); -// -// @Override -//

NativeQuery setParameter(QueryParameter

parameter, P val, Type type); - - - @Override - NativeQuery setParameter(String name, Object val, TemporalType temporalType); - - @Override - NativeQuery setParameter(int position, Object val, TemporalType temporalType); - - @Override -

NativeQuery setParameter(QueryParameter

parameter, P val, TemporalType temporalType); - - @Override - NativeQuery setParameter( - Parameter param, - Calendar value, - TemporalType temporalType); - - @Override - NativeQuery setParameter(Parameter param, Date value, TemporalType temporalType); - - @Override - NativeQuery setParameter(String name, Calendar value, TemporalType temporalType); - - @Override - NativeQuery setParameter(int position, Calendar value, TemporalType temporalType); - - @Override - NativeQuery setParameter(String name, Date value, TemporalType temporalType); - - @Override - NativeQuery setParameter(int position, Date value, TemporalType temporalType); - - @Override -

NativeQuery setParameterList(QueryParameter

parameter, Collection

values); - - @Override - NativeQuery setParameterList(String name, @SuppressWarnings("rawtypes") Collection values); - -// @Override -// default NativeQuery setParameterList(String name, Collection values, Type type) { -// return setParameterList( name, values, (AllowableParameterType) type ); -// } - - @Override -

NativeQuery setParameterList(String name, Collection values, AllowableParameterType

type); - -// @Override -// NativeQuery setParameterList(String name, Object[] values, Type type); - - @Override - NativeQuery setParameterList(String name, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type); - - @Override - NativeQuery setParameterList(String name, Object[] values); +

NativeQuery setParameter(String name, P val, Class

type); @Override

NativeQuery setParameter(String name, P val, AllowableParameterType

type); + @Override + NativeQuery setParameter(String name, Instant value, TemporalType temporalType); + + @Override + NativeQuery setParameter(String name, Calendar value, TemporalType temporalType); + + @Override + NativeQuery setParameter(String name, Date value, TemporalType temporalType); + + @Override + NativeQuery setParameter(int position, Object value); + + @Override +

NativeQuery setParameter(int position, P val, Class

type); + @Override

NativeQuery setParameter(int position, P val, AllowableParameterType

type); + @Override + NativeQuery setParameter(int position, Instant value, TemporalType temporalType); + + @Override + NativeQuery setParameter(int position, Calendar value, TemporalType temporalType); + + @Override + NativeQuery setParameter(int position, Date value, TemporalType temporalType); + + @Override +

NativeQuery setParameter(QueryParameter

parameter, P val); + + @Override +

NativeQuery setParameter(QueryParameter

parameter, P val, Class

type); + @Override

NativeQuery setParameter(QueryParameter

parameter, P val, AllowableParameterType

type); @Override -

NativeQuery setParameter(String name, P val, BasicTypeReference

type); +

NativeQuery setParameter(Parameter

param, P value); @Override -

NativeQuery setParameter(int position, P val, BasicTypeReference

type); + NativeQuery setParameter(Parameter param, Calendar value, TemporalType temporalType); @Override -

NativeQuery setParameter(QueryParameter

parameter, P val, BasicTypeReference

type); + NativeQuery setParameter(Parameter param, Date value, TemporalType temporalType); @Override - NativeQuery setParameterList(int position, @SuppressWarnings("rawtypes") Collection values); + NativeQuery setParameterList(String name, @SuppressWarnings("rawtypes") Collection values); @Override

NativeQuery setParameterList(String name, Collection values, Class

type); + @Override +

NativeQuery setParameterList(String name, Collection values, AllowableParameterType

type); + + @Override + NativeQuery setParameterList(String name, Object[] values); + + @Override +

NativeQuery setParameterList(String name, P[] values, Class

type); + + @Override +

NativeQuery setParameterList(String name, P[] values, AllowableParameterType

type); + + @Override + NativeQuery setParameterList(int position, @SuppressWarnings("rawtypes") Collection values); + @Override

NativeQuery setParameterList(int position, Collection values, Class

type); -// @Override -// NativeQuery setParameterList(int position, Collection values, Type type); - @Override -

NativeQuery setParameterList(int position, Collection values, AllowableParameterType

type); - -// @Override -// NativeQuery setParameterList(int position, Object[] values, Type type); - - @Override - NativeQuery setParameterList(int position, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type); +

NativeQuery setParameterList(int position, Collection values, AllowableParameterType

javaType); @Override NativeQuery setParameterList(int position, Object[] values); + @Override +

NativeQuery setParameterList(int position, P[] values, Class

javaType); + + @Override +

NativeQuery setParameterList(int position, P[] values, AllowableParameterType

javaType); + + @Override +

NativeQuery setParameterList(QueryParameter

parameter, Collection values); + + @Override +

NativeQuery setParameterList(QueryParameter

parameter, Collection values, Class

javaType); + + @Override +

NativeQuery setParameterList(QueryParameter

parameter, Collection values, AllowableParameterType

type); + + @Override +

NativeQuery setParameterList(QueryParameter

parameter, P[] values); + + @Override +

NativeQuery setParameterList(QueryParameter

parameter, P[] values, Class

javaType); + + @Override +

NativeQuery setParameterList(QueryParameter

parameter, P[] values, AllowableParameterType

type); + @Override NativeQuery setProperties(Object bean); diff --git a/hibernate-core/src/main/java/org/hibernate/query/ParameterMetadata.java b/hibernate-core/src/main/java/org/hibernate/query/ParameterMetadata.java index 6661ac8f5a..55d938230e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/ParameterMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/query/ParameterMetadata.java @@ -11,7 +11,6 @@ import java.util.function.Consumer; import jakarta.persistence.Parameter; import org.hibernate.Incubating; -import org.hibernate.metamodel.model.domain.AllowableParameterType; /** diff --git a/hibernate-core/src/main/java/org/hibernate/query/Query.java b/hibernate-core/src/main/java/org/hibernate/query/Query.java index a1a3a5d019..2420fba434 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/Query.java +++ b/hibernate-core/src/main/java/org/hibernate/query/Query.java @@ -7,9 +7,6 @@ package org.hibernate.query; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.OffsetDateTime; -import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Collection; import java.util.Date; @@ -17,11 +14,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Stream; -import jakarta.persistence.FlushModeType; -import jakarta.persistence.LockModeType; -import jakarta.persistence.Parameter; -import jakarta.persistence.TemporalType; -import jakarta.persistence.TypedQuery; import org.hibernate.CacheMode; import org.hibernate.FlushMode; @@ -35,10 +27,14 @@ import org.hibernate.SharedSessionContract; import org.hibernate.dialect.Dialect; import org.hibernate.graph.GraphSemantic; import org.hibernate.graph.RootGraph; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.query.spi.QueryOptions; import org.hibernate.transform.ResultTransformer; -import org.hibernate.type.BasicTypeReference; + +import jakarta.persistence.FlushModeType; +import jakarta.persistence.LockModeType; +import jakarta.persistence.Parameter; +import jakarta.persistence.TemporalType; +import jakarta.persistence.TypedQuery; /** * Represents an HQL/JPQL query or a compiled Criteria query. Also acts as the Hibernate @@ -334,57 +330,116 @@ public interface Query extends TypedQuery, CommonQueryContract { */ ParameterMetadata getParameterMetadata(); + + /** - * Bind the given argument to a named query parameter, inferring the - * {@link AllowableParameterType}. + * Bind the given argument to a named query parameter *

* If the type of the parameter cannot be inferred from the context in which - * it occurs, {@link #setParameter(String, Object, AllowableParameterType)} - * must be used instead. + * it occurs, use one of the forms accept a "type". * - * @param name the parameter name - * @param value the argument, which might be null - * - * @return {@code this}, for method chaining + * @see #setParameter(String, Object, Class) + * @see #setParameter(String, Object, AllowableParameterType) */ @Override Query setParameter(String name, Object value); /** - * Bind the given argument to a positional query parameter, inferring the + * Bind the given argument to a named query parameter using the given + * Class reference to attempt to determine the {@link AllowableParameterType} + * to use. If unable to determine an appropriate {@link AllowableParameterType}, + * {@link #setParameter(String, Object)} is used + * + * @see AllowableParameterType#parameterType(Class) + * @see #setParameter(String, Object, AllowableParameterType) + */ +

Query setParameter(String name, P value, Class

type); + + /** + * Bind the given argument to a named query parameter using the given * {@link AllowableParameterType}. + * + * @see AllowableParameterType#parameterType + */ +

Query setParameter(String name, P value, AllowableParameterType

type); + + /** + * Bind an {@link Instant} value to the named query parameter using just the portion + * indicated by the given {@link TemporalType}. + */ + Query setParameter(String name, Instant value, TemporalType temporalType); + + /** + * {@link jakarta.persistence.Query} override + */ + @Override + Query setParameter(String name, Calendar value, TemporalType temporalType); + + /** + * {@link jakarta.persistence.Query} override + */ + @Override + Query setParameter(String name, Date value, TemporalType temporalType); + + + + /** + * Bind the given argument to a positional query parameter. *

* If the type of the parameter cannot be inferred from the context in which - * it occurs, {@link #setParameter(int, Object, AllowableParameterType)} - * must be used instead. + * it occurs, use one of the forms accept a "type". * - * @param position the positional parameter label - * @param value the argument, which might be null - * - * @return {@code this}, for method chaining + * @see #setParameter(int, Object, Class) + * @see #setParameter(int, Object, AllowableParameterType) */ @Override Query setParameter(int position, Object value); /** - * Bind the given argument to the query parameter represented by the given - * {@link Parameter} object. + * Bind the given argument to a positional query parameter using the given + * Class reference to attempt to determine the {@link AllowableParameterType} + * to use. If unable to determine an appropriate {@link AllowableParameterType}, + * {@link #setParameter(int, Object)} is used * - * @param param the {@link Parameter}. - * @param value the argument, which might be null + * @see AllowableParameterType#parameterType(Class) + * @see #setParameter(int, Object, AllowableParameterType) + */ +

Query setParameter(int position, P value, Class

type); + + /** + * Bind the given argument to a positional query parameter using the given + * {@link AllowableParameterType}. * - * @return {@code this}, for method chaining + * @see AllowableParameterType#parameterType + */ +

Query setParameter(int position, P value, AllowableParameterType

type); + + /** + * Bind an {@link Instant} value to the positional query parameter using just the portion + * indicated by the given {@link TemporalType}. + */ + Query setParameter(int position, Instant value, TemporalType temporalType); + + /** + * {@link jakarta.persistence.Query} override */ @Override - Query setParameter(Parameter param, T value); + Query setParameter(int position, Date value, TemporalType temporalType); + + /** + * {@link jakarta.persistence.Query} override + */ + @Override + Query setParameter(int position, Calendar value, TemporalType temporalType); /** * Bind an argument to the query parameter represented by the given - * {@link QueryParameter}, inferring the {@link AllowableParameterType}. + * {@link QueryParameter}. *

* If the type of the parameter cannot be inferred from the context in which - * it occurs, {@link #setParameter(QueryParameter, Object, AllowableParameterType)} - * must be used instead. + * it occurs, use on of the forms accept a "type". + * + * @see #setParameter(QueryParameter, Object, AllowableParameterType) * * @param parameter the query parameter memento * @param value the argument, which might be null @@ -394,140 +449,205 @@ public interface Query extends TypedQuery, CommonQueryContract { Query setParameter(QueryParameter parameter, T value); /** - * Bind the given argument to a named query parameter using the given - * {@link AllowableParameterType}. + * Bind an argument to the query parameter represented by the given + * {@link QueryParameter} using the given Class reference to attempt to + * determine the {@link AllowableParameterType} to use. If unable to determine + * an appropriate {@link AllowableParameterType}, {@link #setParameter(QueryParameter, Object)} is used * - * @param name the name of the parameter + * @param parameter the query parameter memento * @param value the argument, which might be null - * @param type an {@link AllowableParameterType} representing the type of the parameter + * @param type a {@link AllowableParameterType} representing the type of the parameter * * @return {@code this}, for method chaining + * + * @see AllowableParameterType#parameterType(Class) + * @see #setParameter(QueryParameter, Object, AllowableParameterType) */ -

Query setParameter(String name, P value, AllowableParameterType

type); - - /** - * Bind the given argument to a positional query parameter using the given - * {@link AllowableParameterType}. - * - * @param position the positional parameter label - * @param value the argument, which might be null - * @param type an {@link AllowableParameterType} representing the type of the parameter - * - * @return {@code this}, for method chaining - */ -

Query setParameter(int position, P value, AllowableParameterType

type); - - /** - * Bind the given argument to a named query parameter using the given - * {@link BasicTypeReference}. - * - * @param name the name of the parameter - * @param value the argument, which might be null - * @param type a {@link BasicTypeReference} representing the type of the parameter - * - * @return {@code this}, for method chaining - */ -

Query setParameter(String name, P value, BasicTypeReference

type); - - /** - * Bind the given argument to a positional query parameter using the given - * {@link BasicTypeReference}. - * - * @param position the positional parameter label - * @param value the argument, which might be null - * @param type a {@link BasicTypeReference} representing the type of the parameter - * - * @return {@code this}, for method chaining - */ -

Query setParameter(int position, P value, BasicTypeReference

type); +

Query setParameter(QueryParameter

parameter, P value, Class

type); /** * Bind an argument to the query parameter represented by the given * {@link QueryParameter} using the given {@link AllowableParameterType}. * * @param parameter the query parameter memento - * @param value the argument, which might be null + * @param val the argument, which might be null * @param type an {@link AllowableParameterType} representing the type of the parameter * * @return {@code this}, for method chaining */ -

Query setParameter(QueryParameter

parameter, P value, AllowableParameterType

type); +

Query setParameter(QueryParameter

parameter, P val, AllowableParameterType

type); /** - * Bind an argument to the query parameter represented by the given - * {@link QueryParameter} using the given {@link BasicTypeReference}. - * - * @param parameter the query parameter memento - * @param val the argument, which might be null - * @param type an {@link BasicTypeReference} representing the type of the parameter - * - * @return {@code this}, for method chaining + * {@link jakarta.persistence.Query} override */ -

Query setParameter(QueryParameter

parameter, P val, BasicTypeReference

type); + @Override + Query setParameter(Parameter param, T value); /** - * Bind multiple arguments to a named query parameter, inferring the - * {@link AllowableParameterType}. This is used for binding a list of - * values to an expression such as {@code entity.field in (:values)}. - *

- * The type of the parameter is inferred from the context in which it - * occurs, and from the type of the first given argument. + * {@link jakarta.persistence.Query} override + */ + @Override + Query setParameter(Parameter param, Calendar value, TemporalType temporalType); + + /** + * {@link jakarta.persistence.Query} override + */ + @Override + Query setParameter(Parameter param, Date value, TemporalType temporalType); + + + + /** + * Bind multiple arguments to a named query parameter. + *

+ * The "type mapping" for the binding is inferred from the type of + * the first collection element * - * @param name the name of the parameter - * @param values a collection of arguments + * @see #setParameterList(java.lang.String, java.util.Collection, org.hibernate.query.AllowableParameterType) + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. * * @return {@code this}, for method chaining */ Query setParameterList(String name, @SuppressWarnings("rawtypes") Collection values); /** - * Bind multiple arguments to a positional query parameter, inferring - * the {@link AllowableParameterType}. This is used for binding a list - * of values to an expression such as {@code entity.field in (?1)}. - *

- * The type of the parameter is inferred from the context in which it - * occurs, and from the type of the first given argument. + * Bind multiple arguments to a named query parameter using the given + * Class reference to attempt to determine the {@link AllowableParameterType} + * to use. If unable to determine an appropriate {@link AllowableParameterType}, + * {@link #setParameterList(String, Collection)} is used * - * @param position the parameter positional label - * @param values a collection of arguments + * @see AllowableParameterType#parameterType(Class) + * @see #setParameterList(java.lang.String, java.util.Collection, org.hibernate.query.AllowableParameterType) + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. * * @return {@code this}, for method chaining */ - Query setParameterList(int position, @SuppressWarnings("rawtypes") Collection values); +

Query setParameterList(String name, Collection values, Class

javaType); /** - * Bind multiple arguments to a named query parameter, inferring the - * {@link AllowableParameterType}. This is used for binding a list of - * values to an expression such as {@code entity.field in (:values)}. - *

- * The type of the parameter is inferred from the context in which it - * occurs, and from the type of the first given argument. + * Bind multiple arguments to a named query parameter using the passed type-mapping. * - * @param name the name of the parameter - * @param values an array of arguments + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. + * + * @return {@code this}, for method chaining + */ +

Query setParameterList(String name, Collection values, AllowableParameterType

type); + + + /** + * Bind multiple arguments to a named query parameter. + *

+ * The "type mapping" for the binding is inferred from the type of + * the first collection element + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. * * @return {@code this}, for method chaining */ Query setParameterList(String name, Object[] values); /** - * Bind multiple arguments to a positional query parameter, inferring - * the {@link AllowableParameterType}. This is used for binding a list - * of values to an expression such as {@code entity.field in (?1)}. - *

- * The type of the parameter is inferred from the context in which it - * occurs, and from the type of the first given argument. + * Bind multiple arguments to a named query parameter using the given + * Class reference to attempt to determine the {@link AllowableParameterType} + * to use. If unable to determine an appropriate {@link AllowableParameterType}, + * {@link #setParameterList(String, Collection)} is used * - * @param position the positional parameter label - * @param values an array of arguments + * @see AllowableParameterType#parameterType(Class) + * @see #setParameterList(java.lang.String, Object[], org.hibernate.query.AllowableParameterType) + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. + * + * @return {@code this}, for method chaining + */ +

Query setParameterList(String name, P[] values, Class

javaType); + + + /** + * Bind multiple arguments to a named query parameter using the passed type-mapping. + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. + * + * @return {@code this}, for method chaining + */ +

Query setParameterList(String name, P[] values, AllowableParameterType

type); + + /** + * Bind multiple arguments to a positional query parameter. + *

+ * The "type mapping" for the binding is inferred from the type of + * the first collection element + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. + * + * @return {@code this}, for method chaining + */ + Query setParameterList(int position, @SuppressWarnings("rawtypes") Collection values); + + /** + * Bind multiple arguments to a positional query parameter using the given + * Class reference to attempt to determine the {@link AllowableParameterType} + * to use. If unable to determine an appropriate {@link AllowableParameterType}, + * {@link #setParameterList(String, Collection)} is used + * + * @see AllowableParameterType#parameterType(Class) + * @see #setParameterList(int, Collection, org.hibernate.query.AllowableParameterType) + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. + * + * @return {@code this}, for method chaining + */ +

Query setParameterList(int position, Collection values, Class

javaType); + + /** + * Bind multiple arguments to a positional query parameter using the passed type-mapping. + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. + * + * @return {@code this}, for method chaining + */ +

Query setParameterList(int position, Collection values, AllowableParameterType

type); + + /** + * Bind multiple arguments to a positional query parameter. + *

+ * The "type mapping" for the binding is inferred from the type of + * the first collection element + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. * * @return {@code this}, for method chaining */ Query setParameterList(int position, Object[] values); + /** + * Bind multiple arguments to a positional query parameter using the given + * Class reference to attempt to determine the {@link AllowableParameterType} + * to use. If unable to determine an appropriate {@link AllowableParameterType}, + * {@link #setParameterList(String, Collection)} is used + * + * @see AllowableParameterType#parameterType(Class) + * @see #setParameterList(int, Object[], org.hibernate.query.AllowableParameterType) + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. + * + * @return {@code this}, for method chaining + */ +

Query setParameterList(int position, P[] values, Class

javaType); + + /** + * Bind multiple arguments to a positional query parameter using the passed type-mapping. + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. + * + * @return {@code this}, for method chaining + */ +

Query setParameterList(int position, P[] values, AllowableParameterType

type); + /** * Bind multiple arguments to the query parameter represented by the - * given {@link QueryParameter}, inferring the {@link AllowableParameterType}. + * given {@link QueryParameter}. *

* The type of the parameter is inferred from the context in which it * occurs, and from the type of the first given argument. @@ -537,92 +657,84 @@ public interface Query extends TypedQuery, CommonQueryContract { * * @return {@code this}, for method chaining */ -

Query setParameterList(QueryParameter

parameter, Collection

values); +

Query setParameterList(QueryParameter

parameter, Collection values); /** - * Bind multiple arguments to a named query parameter, inferring the - * {@link AllowableParameterType}. This is used for binding a list of - * values to an expression such as {@code entity.field in (:values)}. + * Bind multiple arguments to the query parameter represented by the + * given {@link QueryParameter} using the given Class reference to attempt + * to determine the {@link AllowableParameterType} to use. If unable to + * determine an appropriate {@link AllowableParameterType}, + * {@link #setParameterList(String, Collection)} is used + * + * @see AllowableParameterType#parameterType(Class) + * @see #setParameterList(QueryParameter, java.util.Collection, org.hibernate.query.AllowableParameterType) + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. + * + * @return {@code this}, for method chaining + */ +

Query setParameterList(QueryParameter

parameter, Collection values, Class

javaType); + + /** + * Bind multiple arguments to the query parameter represented by the + * given {@link QueryParameter}, inferring the {@link AllowableParameterType}. + * + * Bind multiple arguments to a named query parameter. + *

+ * The "type mapping" for the binding is inferred from the type of + * the first collection element + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. + * + * @return {@code this}, for method chaining + */ +

Query setParameterList(QueryParameter

parameter, Collection values, AllowableParameterType

type); + + /** + * Bind multiple arguments to the query parameter represented by the + * given {@link QueryParameter} *

- * The type of the parameter is inferred from the context in which it - * occurs, and from the type represented by the given class object. + * The type of the parameter is inferred between the context in which it + * occurs, the type associated with the QueryParameter and the type of + * the first given argument. * - * @param name the name of the parameter + * @param parameter the parameter memento * @param values a collection of arguments - * @param type the Java class of the arguments * * @return {@code this}, for method chaining */ -

Query setParameterList(String name, Collection values, Class

type); +

Query setParameterList(QueryParameter

parameter, P[] values); /** - * Bind multiple arguments to a positional query parameter, inferring - * the {@link AllowableParameterType}. This is used for binding a list - * of values to an expression such as {@code entity.field in (?1)}. - *

- * The type of the parameter is inferred from the context in which it - * occurs, and from the type represented by the given class object. + * Bind multiple arguments to the query parameter represented by the + * given {@link QueryParameter} using the given Class reference to attempt + * to determine the {@link AllowableParameterType} to use. If unable to + * determine an appropriate {@link AllowableParameterType}, + * {@link #setParameterList(String, Collection)} is used * - * @param position the positional parameter label - * @param values a collection of arguments - * @param type the Java class of the arguments + * @see AllowableParameterType#parameterType(Class) + * @see #setParameterList(QueryParameter, Object[], org.hibernate.query.AllowableParameterType) + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. * * @return {@code this}, for method chaining */ -

Query setParameterList(int position, Collection values, Class

type); +

Query setParameterList(QueryParameter

parameter, P[] values, Class

javaType); /** - * Bind multiple arguments to a named query parameter, using the given - * {@link AllowableParameterType}. This is used for binding a list of - * values to an expression such as {@code entity.field in (?1)}. + * Bind multiple arguments to the query parameter represented by the + * given {@link QueryParameter}, inferring the {@link AllowableParameterType}. * - * @param name the name of the parameter - * @param values a collection of arguments - * @param type an {@link AllowableParameterType} representing the type of the parameter + * Bind multiple arguments to a named query parameter. + *

+ * The "type mapping" for the binding is inferred from the type of + * the first collection element + * + * @apiNote This is used for binding a list of values to an expression such as {@code entity.field in (:values)}. * * @return {@code this}, for method chaining */ -

Query setParameterList(String name, Collection values, AllowableParameterType

type); - - /** - * Bind multiple arguments to a positional query parameter, using the - * given {@link AllowableParameterType}. This is used for binding a list - * of values to an expression such as {@code entity.field in (?1)}. - * - * @param position the positional parameter label - * @param values a collection of arguments - * @param type an {@link AllowableParameterType} representing the type of the parameter - * - * @return {@code this}, for method chaining - */ -

Query setParameterList(int position, Collection values, AllowableParameterType

type); - - /** - * Bind multiple arguments to a named query parameter, using the given - * {@link AllowableParameterType}. This is used for binding a list of - * values to an expression such as {@code entity.field in (?1)}. - * - * @param name the name of the parameter - * @param values an array of arguments - * @param type an {@link AllowableParameterType} representing the type of the parameter - * - * @return {@code this}, for method chaining - */ - Query setParameterList(String name, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type); - - /** - * Bind multiple arguments to a positional query parameter, using the - * given {@link AllowableParameterType}. This is used for binding a list - * of values to an expression such as {@code entity.field in (?1)}. - * - * @param position the positional parameter label - * @param values an array of arguments - * @param type an {@link AllowableParameterType} representing the type of the parameter - * - * - * @return {@code this}, for method chaining - */ - Query setParameterList(int position, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type); +

Query setParameterList(QueryParameter

parameter, P[] values, AllowableParameterType

type); /** * Bind the property values of the given bean to named parameters of the query, @@ -646,6 +758,7 @@ public interface Query extends TypedQuery, CommonQueryContract { */ Query setProperties(@SuppressWarnings("rawtypes") Map bean); + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // covariant overrides - CommonQueryContract @@ -670,6 +783,7 @@ public interface Query extends TypedQuery, CommonQueryContract { @Override Query setReadOnly(boolean readOnly); + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // covariant overrides - jakarta.persistence.Query/TypedQuery @@ -688,6 +802,7 @@ public interface Query extends TypedQuery, CommonQueryContract { @Override Query setLockMode(LockModeType lockMode); + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // deprecated methods @@ -702,181 +817,4 @@ public interface Query extends TypedQuery, CommonQueryContract { return this; } - /** - * Bind a positional query parameter as some form of date/time using - * the indicated temporal-type. - * - * @param position the position of the parameter in the query string - * @param val the possibly-null parameter value - * @param temporalType the temporal-type to use in binding the date/time - * - * @return {@code this}, for method chaining - * - * @deprecated use {@link #setParameter(int, Object)} - * passing a {@link java.time.LocalDate}, {@link java.time.LocalTime}, - * or {@link java.time.LocalDateTime} - */ - @Deprecated - Query setParameter(int position, Object val, TemporalType temporalType); - - /** - * Bind a named query parameter as some form of date/time using - * the indicated temporal-type. - * - * @param name the parameter name - * @param val the possibly-null parameter value - * @param temporalType the temporal-type to use in binding the date/time - * - * @return {@code this}, for method chaining - * - * @deprecated use {@link #setParameter(String, Object)} - * passing a {@link java.time.LocalDate}, {@link java.time.LocalTime}, - * or {@link java.time.LocalDateTime} - */ - @Deprecated - Query setParameter(String name, Object val, TemporalType temporalType); - - /** - * Bind a query parameter as some form of date/time using the indicated - * temporal-type. - * - * @param parameter The query parameter memento - * @param val the possibly-null parameter value - * @param temporalType the temporal-type to use in binding the date/time - * - * @return {@code this}, for method chaining - * - * @deprecated use {@link #setParameter(int, Object)} - * passing a {@link java.time.LocalDate}, {@link java.time.LocalTime}, - * or {@link java.time.LocalDateTime} - */ - @Deprecated -

Query setParameter(QueryParameter

parameter, P val, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(Parameter, Object)} - */ - @Override @Deprecated - Query setParameter(Parameter param, Calendar value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(Parameter, Object)}, - * passing a {@link java.time.LocalDate}, {@link java.time.LocalTime}, - * or {@link java.time.LocalDateTime} - */ - @Override @Deprecated - Query setParameter(Parameter param, Date value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(String, Object)}, - * passing a {@link java.time.LocalDate}, {@link java.time.LocalTime}, - * or {@link java.time.LocalDateTime} - */ - @Override @Deprecated - Query setParameter(String name, Calendar value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(String, Object)} - * passing a {@link java.time.LocalDate}, {@link java.time.LocalTime}, - * or {@link java.time.LocalDateTime} - */ - @Override @Deprecated - Query setParameter(String name, Date value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(int, Object)} - * passing a {@link java.time.LocalDate}, {@link java.time.LocalTime}, - * or {@link java.time.LocalDateTime} - */ - @Override @Deprecated - Query setParameter(int position, Calendar value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(int, Object)} - * passing a {@link java.time.LocalDate}, {@link java.time.LocalTime}, - * or {@link java.time.LocalDateTime} - */ - @Override @Deprecated - Query setParameter(int position, Date value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(Parameter, Object)} - */ - @Deprecated - Query setParameter(Parameter param, Instant value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(Parameter, Object)} - */ - @Deprecated - Query setParameter( - Parameter param, - LocalDateTime value, - TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(Parameter, Object)} - */ - @Deprecated - Query setParameter( - Parameter param, - ZonedDateTime value, - TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(Parameter, Object)} - */ - @Deprecated - Query setParameter( - Parameter param, - OffsetDateTime value, - TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(String, Object)} - */ - @Deprecated - Query setParameter(String name, Instant value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(String, Object)} - */ - @Deprecated - Query setParameter(String name, LocalDateTime value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(String, Object)} - */ - @Deprecated - Query setParameter(String name, ZonedDateTime value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(String, Object)} - */ - @Deprecated - Query setParameter(String name, OffsetDateTime value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(int, Object)} - */ - @Deprecated - Query setParameter(int position, Instant value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(int, Object)} - */ - @Deprecated - Query setParameter(int position, LocalDateTime value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(int, Object)} - */ - @Deprecated - Query setParameter(int position, ZonedDateTime value, TemporalType temporalType); - - /** - * @deprecated use {@link #setParameter(int, Object)} - */ - @Deprecated - Query setParameter(int position, OffsetDateTime value, TemporalType temporalType); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/QueryParameter.java b/hibernate-core/src/main/java/org/hibernate/query/QueryParameter.java index 71664a2dec..b9bb78113b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/QueryParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/QueryParameter.java @@ -7,7 +7,6 @@ package org.hibernate.query; import org.hibernate.Incubating; -import org.hibernate.metamodel.model.domain.AllowableParameterType; /** * Represents a parameter defined in the source (HQL/JPQL or criteria) query. diff --git a/hibernate-core/src/main/java/org/hibernate/query/TypedParameterValue.java b/hibernate-core/src/main/java/org/hibernate/query/TypedParameterValue.java index c8b0d23c92..10e4181380 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/TypedParameterValue.java +++ b/hibernate-core/src/main/java/org/hibernate/query/TypedParameterValue.java @@ -7,11 +7,10 @@ package org.hibernate.query; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.type.BasicTypeReference; /** - * Can be used to bind query parameter values. Allows to provide additional details about the + * Can be used to bind query parameter values. Allows providing additional details about the * parameter value/binding. * * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java index d4abd3084b..3d78e0f24b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java @@ -406,65 +406,6 @@ public interface HibernateCriteriaBuilder extends CriteriaBuilder { @Override JpaSearchedCase selectCase(); - /** - * Create a tuple, as in a composite value, usable in any - * part of the query. - * - * @apiNote This is different from the purely JPA form - * {@link CriteriaBuilder#tuple} which is intended only for use as - * the selection in a root query. - * - * @param tupleType The Java type - * @param expressions The individual expressions making up the tuple - */ - JpaCompoundSelection tuple( - Class tupleType, - JpaExpression... expressions); - - /** - * Create a tuple, as in a composite value, usable in any - * part of the query. - * - * @apiNote This is different from the purely JPA form - * {@link CriteriaBuilder#tuple} which is intended only for use as - * the selection in a root query. - *@param tupleType The Java type - * @param expressions The individual expressions making up the tuple - */ - JpaCompoundSelection tuple( - Class tupleType, - List> expressions); - - /** - * Create a tuple, as in a composite value, usable in any - * part of the query. - * - * @apiNote This is different from the purely JPA form - * {@link CriteriaBuilder#tuple} which is intended only for use as - * the selection in a root query. - * - * @param tupleType The metamodel DomainType descriptor to apply to the tuple - * @param expressions The individual expressions making up the tuple - */ - JpaCompoundSelection tuple( - DomainType tupleType, - JpaExpression... expressions); - - /** - * Create a tuple, as in a composite value, usable in any - * part of the query. - * - * @apiNote This is different from the purely JPA form - * {@link CriteriaBuilder#tuple} which is intended only for use as - * the selection in a root query. - * - * @param tupleType The metamodel DomainType descriptor to apply to the tuple - * @param expressions The individual expressions making up the tuple - */ - JpaCompoundSelection tuple( - DomainType tupleType, - List> expressions); - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Predicates diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index 4cc8de5a26..ae13bd4688 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -47,7 +47,7 @@ import org.hibernate.internal.util.collections.Stack; import org.hibernate.internal.util.collections.StandardStack; import org.hibernate.metamodel.CollectionClassification; import org.hibernate.metamodel.mapping.CollectionPart; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractQueryParameterImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractQueryParameterImpl.java index 3b84a9be2b..bb6c9975a4 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractQueryParameterImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractQueryParameterImpl.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.internal; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.QueryParameter; /** @@ -31,11 +31,14 @@ public abstract class AbstractQueryParameterImpl implements QueryParameter public void setHibernateType(AllowableParameterType expectedType) { //noinspection unchecked - this.expectedType = (AllowableParameterType) expectedType; + this.expectedType = (AllowableParameterType) expectedType; } @Override public Class getParameterType() { - return expectedType == null ? null : expectedType.getExpressableJavaTypeDescriptor().getJavaTypeClass(); + if ( expectedType == null ) { + return null; + } + return expectedType.getBindableJavaType(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/BindingTypeHelper.java b/hibernate-core/src/main/java/org/hibernate/query/internal/BindingTypeHelper.java index 6a2cdfd0f6..53d5defd0a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/BindingTypeHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/BindingTypeHelper.java @@ -11,14 +11,17 @@ import java.time.OffsetDateTime; import java.time.OffsetTime; import java.time.ZonedDateTime; import java.util.Calendar; -import jakarta.persistence.TemporalType; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.JdbcMapping; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.java.TemporalJavaTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; +import jakarta.persistence.TemporalType; + /** * @author Steve Ebersole */ @@ -34,21 +37,25 @@ public class BindingTypeHelper { public AllowableParameterType resolveTemporalPrecision( TemporalType precision, AllowableParameterType declaredParameterType, - TypeConfiguration typeConfiguration) { + SessionFactoryImplementor sessionFactory) { if ( precision != null ) { - if ( !( declaredParameterType.getExpressableJavaTypeDescriptor() instanceof TemporalJavaTypeDescriptor ) ) { + final SqmExpressable sqmExpressable = declaredParameterType.resolveExpressable( sessionFactory ); + if ( !( sqmExpressable.getExpressableJavaTypeDescriptor() instanceof TemporalJavaTypeDescriptor ) ) { throw new UnsupportedOperationException( "Cannot treat non-temporal parameter type with temporal precision" ); } - final TemporalJavaTypeDescriptor temporalJtd = (TemporalJavaTypeDescriptor) declaredParameterType.getExpressableJavaTypeDescriptor(); + + final TemporalJavaTypeDescriptor temporalJtd = (TemporalJavaTypeDescriptor) sqmExpressable.getExpressableJavaTypeDescriptor(); if ( temporalJtd.getPrecision() != precision ) { + final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration(); return typeConfiguration.getBasicTypeRegistry().resolve( temporalJtd.resolveTypeForPrecision( precision, typeConfiguration ), TemporalJavaTypeDescriptor.resolveJdbcTypeCode( precision ) ); } } + return declaredParameterType; } @@ -78,12 +85,12 @@ public class BindingTypeHelper { } } + @SuppressWarnings({ "rawtypes", "unchecked" }) public AllowableParameterType resolveTimestampTemporalTypeVariant( Class javaType, AllowableParameterType baseType, TypeConfiguration typeConfiguration) { - //noinspection unchecked - if ( baseType.getExpressableJavaTypeDescriptor().getJavaTypeClass().isAssignableFrom( javaType ) ) { + if ( baseType.getBindableJavaType().isAssignableFrom( javaType ) ) { return baseType; } @@ -118,7 +125,7 @@ public class BindingTypeHelper { Class javaType, AllowableParameterType baseType, TypeConfiguration typeConfiguration) { - if ( baseType.getExpressableJavaTypeDescriptor().getJavaTypeClass().isAssignableFrom( javaType ) ) { + if ( baseType.getBindableJavaType().isAssignableFrom( javaType ) ) { return baseType; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java index 44bc92204e..ac22c1f6a0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java @@ -22,7 +22,7 @@ import org.hibernate.QueryException; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.internal.util.compare.ComparableComparator; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.QueryParameter; import org.hibernate.query.spi.ParameterMetadataImplementor; import org.hibernate.query.spi.QueryParameterImplementor; diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingImpl.java index 3ed4b10481..ae180daadb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingImpl.java @@ -8,21 +8,23 @@ package org.hibernate.query.internal; import java.util.Collection; import java.util.Iterator; -import jakarta.persistence.TemporalType; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.BasicValuedMapping; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.MappingModelExpressable; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.QueryParameter; import org.hibernate.query.spi.QueryParameterBinding; -import org.hibernate.query.spi.QueryParameterBindingTypeResolver; import org.hibernate.query.spi.QueryParameterBindingValidator; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.type.descriptor.java.CoercionException; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.TemporalJavaTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; +import jakarta.persistence.TemporalType; + /** * The standard Hibernate QueryParameterBinding implementation * @@ -30,7 +32,7 @@ import org.hibernate.type.spi.TypeConfiguration; */ public class QueryParameterBindingImpl implements QueryParameterBinding, JavaType.CoercionContext { private final QueryParameter queryParameter; - private final QueryParameterBindingTypeResolver typeResolver; + private final SessionFactoryImplementor sessionFactory; private final boolean isBindingValidationRequired; private boolean isBound; @@ -43,25 +45,29 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J private T bindValue; private Collection bindValues; - // todo (6.0) : add TemporalType to QueryParameter and use to default precision here - - public QueryParameterBindingImpl( + /** + * Used by {@link org.hibernate.procedure.ProcedureCall} + */ + protected QueryParameterBindingImpl( QueryParameter queryParameter, - QueryParameterBindingTypeResolver typeResolver, + SessionFactoryImplementor sessionFactory, boolean isBindingValidationRequired) { this.queryParameter = queryParameter; - this.typeResolver = typeResolver; + this.sessionFactory = sessionFactory; this.isBindingValidationRequired = isBindingValidationRequired; this.bindType = queryParameter.getHibernateType(); } + /** + * Used by Query (SQM) and NativeQuery + */ public QueryParameterBindingImpl( QueryParameter queryParameter, - QueryParameterBindingTypeResolver typeResolver, + SessionFactoryImplementor sessionFactory, AllowableParameterType bindType, boolean isBindingValidationRequired) { this.queryParameter = queryParameter; - this.typeResolver = typeResolver; + this.sessionFactory = sessionFactory; this.isBindingValidationRequired = isBindingValidationRequired; this.bindType = bindType; } @@ -108,10 +114,10 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J if ( ! getTypeConfiguration().getSessionFactory().getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled() ) { try { if ( bindType != null ) { - value = bindType.getExpressableJavaTypeDescriptor().coerce( value, this ); + value = coerce( value, bindType ); } else if ( queryParameter.getHibernateType() != null ) { - value = queryParameter.getHibernateType().getExpressableJavaTypeDescriptor().coerce( value, this ); + value = coerce( value, queryParameter.getHibernateType() ); } } catch (CoercionException ce) { @@ -119,7 +125,7 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J String.format( "Parameter value [%s] did not match expected type [%s ]", value, - bindType.getTypeName() + bindType ), ce ); @@ -136,6 +142,17 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J bindValue( value ); } + private T coerce(T value, AllowableParameterType parameterType) { + if ( value == null ) { + return null; + } + + final SqmExpressable sqmExpressable = parameterType.resolveExpressable( sessionFactory ); + assert sqmExpressable != null; + + return sqmExpressable.getExpressableJavaTypeDescriptor().coerce( value, this ); + } + private boolean handleAsMultiValue(T value) { if ( ! queryParameter.allowsMultiValuedBinding() ) { return false; @@ -164,7 +181,7 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J if ( bindType == null ) { if ( value != null ) { - this.bindType = typeResolver.resolveParameterBindType( value ); + this.bindType = sessionFactory.resolveParameterBindType( value ); } } } @@ -180,10 +197,10 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J } if ( bindType != null ) { - value = bindType.getExpressableJavaTypeDescriptor().coerce( value, this ); + value = coerce( value, bindType ); } else if ( queryParameter.getHibernateType() != null ) { - value = queryParameter.getHibernateType().getExpressableJavaTypeDescriptor().coerce( value, this ); + value = coerce( value, queryParameter.getHibernateType() ); } if ( isBindingValidationRequired ) { @@ -206,14 +223,14 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J if ( ! getTypeConfiguration().getSessionFactory().getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled() ) { if ( bindType != null ) { try { - value = bindType.getExpressableJavaTypeDescriptor().coerce( value, this ); + value = coerce( value, bindType ); } catch (CoercionException ex) { throw new IllegalArgumentException( String.format( "Parameter value [%s] did not match expected type [%s (%s)]", value, - bindType.getTypeName(), + bindType, temporalTypePrecision == null ? "n/a" : temporalTypePrecision.name() ), ex @@ -221,7 +238,7 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J } } else if ( queryParameter.getHibernateType() != null ) { - value = queryParameter.getHibernateType().getExpressableJavaTypeDescriptor().coerce( value, this ); + value = coerce( value, queryParameter.getHibernateType() ); } } @@ -261,7 +278,7 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J } if ( bindType == null && value != null ) { - this.bindType = typeResolver.resolveParameterBindType( value ); + this.bindType = sessionFactory.resolveParameterBindType( value ); } } @@ -284,18 +301,24 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J } private void setExplicitTemporalPrecision(TemporalType temporalTypePrecision) { - // todo (6.0): what to do with converted attributes? - if ( bindType == null || bindType.getExpressableJavaTypeDescriptor() instanceof TemporalJavaTypeDescriptor ) { + if ( bindType == null || determineJavaType( bindType ) instanceof TemporalJavaTypeDescriptor ) { this.bindType = BindingTypeHelper.INSTANCE.resolveTemporalPrecision( temporalTypePrecision, bindType, - getTypeConfiguration() + sessionFactory ); } this.explicitTemporalPrecision = temporalTypePrecision; } + private JavaType determineJavaType(AllowableParameterType bindType) { + final SqmExpressable sqmExpressable = bindType.resolveExpressable( sessionFactory ); + assert sqmExpressable != null; + + return sqmExpressable.getExpressableJavaTypeDescriptor(); + } + @Override public MappingModelExpressable getType() { return type; @@ -304,7 +327,7 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J @Override @SuppressWarnings("unchecked") public boolean setType(MappingModelExpressable type) { this.type = type; - if ( bindType == null || bindType.getJavaType() == Object.class ) { + if ( bindType == null || bindType.getBindableJavaType() == Object.class ) { if ( type instanceof AllowableParameterType ) { final boolean changed = bindType != null && type != bindType; this.bindType = (AllowableParameterType) type; @@ -323,19 +346,19 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J } private void validate(T value) { - QueryParameterBindingValidator.INSTANCE.validate( getBindType(), value ); + QueryParameterBindingValidator.INSTANCE.validate( getBindType(), value, sessionFactory ); } private void validate(T value, AllowableParameterType clarifiedType) { - QueryParameterBindingValidator.INSTANCE.validate( clarifiedType, value ); + QueryParameterBindingValidator.INSTANCE.validate( clarifiedType, value, sessionFactory ); } private void validate(T value, TemporalType clarifiedTemporalType) { - QueryParameterBindingValidator.INSTANCE.validate( getBindType(), value, clarifiedTemporalType ); + QueryParameterBindingValidator.INSTANCE.validate( getBindType(), value, clarifiedTemporalType, sessionFactory ); } @Override public TypeConfiguration getTypeConfiguration() { - return typeResolver.getTypeConfiguration(); + return sessionFactory.getTypeConfiguration(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java index 069b14a35c..15b9302a44 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java @@ -266,7 +266,7 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings { else if ( binding.getBindValue() != null ) { return typeConfiguration.getBasicTypeForJavaType( binding.getBindValue().getClass() ); } - return typeConfiguration.getBasicTypeForJavaType( binding.getBindType().getJavaType() ); + return typeConfiguration.getBasicTypeForJavaType( binding.getBindType().getBindableJavaType() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterNamedImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterNamedImpl.java index c68a9f4175..6488727333 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterNamedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterNamedImpl.java @@ -8,7 +8,7 @@ package org.hibernate.query.internal; import java.util.Objects; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.AbstractQueryParameter; import org.hibernate.query.named.NamedQueryMemento; import org.hibernate.query.sqm.tree.expression.SqmParameter; diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterPositionalImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterPositionalImpl.java index ed92c250b3..fe743d4433 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterPositionalImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterPositionalImpl.java @@ -9,7 +9,7 @@ package org.hibernate.query.internal; import java.util.Objects; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.AbstractQueryParameter; import org.hibernate.query.named.NamedQueryMemento; import org.hibernate.query.sqm.tree.expression.SqmParameter; 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 aecbca5a64..c4485ab047 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 @@ -8,9 +8,6 @@ package org.hibernate.query.spi; import java.io.Serializable; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.OffsetDateTime; -import java.time.ZonedDateTime; import java.util.Arrays; import java.util.Calendar; import java.util.Collection; @@ -24,13 +21,6 @@ import java.util.Spliterator; import java.util.Spliterators; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import jakarta.persistence.CacheRetrieveMode; -import jakarta.persistence.CacheStoreMode; -import jakarta.persistence.FlushModeType; -import jakarta.persistence.LockModeType; -import jakarta.persistence.NoResultException; -import jakarta.persistence.Parameter; -import jakarta.persistence.TemporalType; import org.hibernate.CacheMode; import org.hibernate.FlushMode; @@ -49,11 +39,11 @@ import org.hibernate.jpa.QueryHints; import org.hibernate.jpa.internal.util.ConfigurationHelper; import org.hibernate.jpa.internal.util.FlushModeTypeHelper; import org.hibernate.jpa.internal.util.LockModeTypeHelper; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.IllegalQueryOperationException; import org.hibernate.query.QueryLogging; import org.hibernate.query.QueryParameter; @@ -62,14 +52,23 @@ import org.hibernate.query.TupleTransformer; import org.hibernate.query.TypedParameterValue; import org.hibernate.query.internal.ScrollableResultsIterator; import org.hibernate.query.named.NamedQueryMemento; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.type.BasicType; -import org.hibernate.type.BasicTypeReference; import org.hibernate.type.descriptor.java.JavaType; +import jakarta.persistence.CacheRetrieveMode; +import jakarta.persistence.CacheStoreMode; +import jakarta.persistence.FlushModeType; +import jakarta.persistence.LockModeType; +import jakarta.persistence.NoResultException; +import jakarta.persistence.Parameter; +import jakarta.persistence.TemporalType; + import static org.hibernate.LockMode.UPGRADE; import static org.hibernate.LockOptions.NONE; import static org.hibernate.LockOptions.READ; import static org.hibernate.LockOptions.WAIT_FOREVER; +import static org.hibernate.annotations.QueryHints.NATIVE_LOCKMODE; import static org.hibernate.cfg.AvailableSettings.JAKARTA_LOCK_SCOPE; import static org.hibernate.cfg.AvailableSettings.JAKARTA_LOCK_TIMEOUT; import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_RETRIEVE_MODE; @@ -79,7 +78,6 @@ import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_TIMEOUT; import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE; import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE; import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; -import static org.hibernate.annotations.QueryHints.NATIVE_LOCKMODE; import static org.hibernate.jpa.QueryHints.HINT_CACHEABLE; import static org.hibernate.jpa.QueryHints.HINT_CACHE_MODE; import static org.hibernate.jpa.QueryHints.HINT_CACHE_REGION; @@ -830,445 +828,6 @@ public abstract class AbstractQuery implements QueryImplementor { } } - @Override - public boolean isBound(Parameter param) { - getSession().checkOpen(); - - final QueryParameterImplementor qp = getParameterMetadata().resolve( param ); - return qp != null && getQueryParameterBindings().isBound( qp ); - } - - @SuppressWarnings( {"WeakerAccess", "unchecked", "rawtypes"} ) - protected

QueryParameterBinding

locateBinding(Parameter

parameter) { - if ( parameter instanceof QueryParameterImplementor ) { - return locateBinding( (QueryParameterImplementor) parameter ); - } - else if ( parameter.getName() != null ) { - return locateBinding( parameter.getName() ); - } - else if ( parameter.getPosition() != null ) { - return locateBinding( parameter.getPosition() ); - } - - throw getSession().getExceptionConverter().convert( - new IllegalArgumentException( "Could not resolve binding for given parameter reference [" + parameter + "]" ) - ); - } - - @SuppressWarnings("WeakerAccess") - protected

QueryParameterBinding

locateBinding(QueryParameterImplementor

parameter) { - getSession().checkOpen(); - return getQueryParameterBindings().getBinding( parameter ); - } - - @SuppressWarnings( {"WeakerAccess"} ) - protected

QueryParameterBinding

locateBinding(String name) { - getSession().checkOpen(); - return getQueryParameterBindings().getBinding( name ); - } - - @SuppressWarnings( {"WeakerAccess"} ) - protected

QueryParameterBinding

locateBinding(int position) { - getSession().checkOpen(); - return getQueryParameterBindings().getBinding( position ); - } - - @Override - public QueryImplementor setParameter(Parameter param, Instant value, TemporalType temporalType) { - locateBinding( param ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(Parameter param, LocalDateTime value, TemporalType temporalType) { - locateBinding( param ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(Parameter param, ZonedDateTime value, TemporalType temporalType) { - locateBinding( param ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(Parameter param, OffsetDateTime value, TemporalType temporalType) { - locateBinding( param ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(String name, Instant value, TemporalType temporalType) { - locateBinding( name ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(String name, LocalDateTime value, TemporalType temporalType) { - locateBinding( name ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(String name, ZonedDateTime value, TemporalType temporalType) { - locateBinding( name ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(String name, OffsetDateTime value, TemporalType temporalType) { - locateBinding( name ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(int position, Instant value, TemporalType temporalType) { - locateBinding( position ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(int position, LocalDateTime value, TemporalType temporalType) { - locateBinding( position ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(int position, ZonedDateTime value, TemporalType temporalType) { - locateBinding( position ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(int position, OffsetDateTime value, TemporalType temporalType) { - locateBinding( position ).setBindValue( value, temporalType ); - return this; - } - - @Override - public

QueryImplementor setParameter(QueryParameter

parameter, P value) { - locateBinding( parameter ).setBindValue( value, resolveJdbcParameterTypeIfNecessary() ); - return this; - } - - @Override - public

QueryImplementor setParameter(Parameter

parameter, P value) { - if ( value instanceof TypedParameterValue ) { - @SuppressWarnings("unchecked") - final TypedParameterValue

typedValue = (TypedParameterValue

) value; - final AllowableParameterType

type = typedValue.getType(); - if ( type != null ) { - setParameter( parameter, typedValue.getValue(), type ); - } - else { - setParameter( parameter, typedValue.getValue(), typedValue.getTypeReference() ); - } - } - else { - locateBinding( parameter ).setBindValue( value, resolveJdbcParameterTypeIfNecessary() ); - } - - return this; - } - - private

void setParameter(Parameter

parameter, P value, BasicTypeReference

type) { - setParameter( parameter, value, session.getTypeConfiguration().getBasicTypeRegistry().resolve( type ) ); - } - - private

void setParameter(Parameter

parameter, P value, AllowableParameterType

type) { - if ( parameter instanceof QueryParameter ) { - setParameter( (QueryParameter

) parameter, value, type ); - } - else if ( value == null ) { - locateBinding( parameter ).setBindValue( null, type ); - } - else if ( value instanceof Collection ) { - //TODO: this looks wrong to me: how can value be both a P and a (Collection

)? - locateBinding( parameter ).setBindValues( (Collection

) value ); - } - else { - locateBinding( parameter ).setBindValue( value, type ); - } - } - - @Override - public QueryImplementor setParameter(String name, Object value) { - if ( value instanceof TypedParameterValue ) { - @SuppressWarnings("unchecked") - final TypedParameterValue typedValue = (TypedParameterValue) value; - final AllowableParameterType type = typedValue.getType(); - if ( type != null ) { - return setParameter( name, typedValue.getValue(), type ); - } - else { - return setParameter( name, typedValue.getValue(), typedValue.getTypeReference() ); - } - } - - final QueryParameterImplementor param = getParameterMetadata().getQueryParameter( name ); - - if ( param == null ) { - throw new IllegalArgumentException( "Named parameter [" + name + "] is not registered with this procedure call" ); - } - - if ( param.allowsMultiValuedBinding() ) { - final AllowableParameterType hibernateType = param.getHibernateType(); - if ( hibernateType == null || ! hibernateType.getExpressableJavaTypeDescriptor().getJavaTypeClass().isInstance( value ) ) { - if ( value instanceof Collection ) { - //noinspection rawtypes - setParameterList( name, (Collection) value ); - } - } - } - - locateBinding( name ).setBindValue( value, resolveJdbcParameterTypeIfNecessary() ); - - return this; - } - - @Override - public QueryImplementor setParameter(int position, Object value) { - if ( value instanceof TypedParameterValue ) { - @SuppressWarnings("unchecked") - final TypedParameterValue typedValue = (TypedParameterValue) value; - final AllowableParameterType type = typedValue.getType(); - if ( type != null ) { - return setParameter( position, typedValue.getValue(), type ); - } - else { - return setParameter( position, typedValue.getValue(), typedValue.getTypeReference() ); - } - } - - final QueryParameterImplementor param = getParameterMetadata().getQueryParameter( position ); - - if ( param == null ) { - throw new IllegalArgumentException( "Positional parameter [" + position + "] is not registered with this procedure call" ); - } - - if ( param.allowsMultiValuedBinding() ) { - final AllowableParameterType hibernateType = param.getHibernateType(); - if ( hibernateType == null || ! hibernateType.getExpressableJavaTypeDescriptor().getJavaTypeClass().isInstance( value ) ) { - if ( value instanceof Collection ) { - //noinspection rawtypes,unchecked - setParameterList( param, (Collection) value ); - } - } - } - - locateBinding( position ).setBindValue( value, resolveJdbcParameterTypeIfNecessary() ); - return this; - } - - @Override - public

QueryImplementor setParameter(QueryParameter

parameter, P value, AllowableParameterType

type) { - locateBinding( parameter ).setBindValue( value, type ); - return this; - } - - @Override - public

QueryImplementor setParameter(String name, P value, AllowableParameterType

type) { - this.

locateBinding( name ).setBindValue( value, type ); - return this; - } - - @Override - public

QueryImplementor setParameter(int position, P value, AllowableParameterType

type) { - this.

locateBinding( position ).setBindValue( value, type ); - return this; - } - - @Override - public

QueryImplementor setParameter(String name, P value, BasicTypeReference

type) { - return setParameter( name, value, session.getTypeConfiguration().getBasicTypeRegistry().resolve( type ) ); - } - - @Override - public

QueryImplementor setParameter(int position, P value, BasicTypeReference

type) { - return setParameter( position, value, session.getTypeConfiguration().getBasicTypeRegistry().resolve( type ) ); - } - - @Override - public

QueryImplementor setParameter(QueryParameter

parameter, P val, BasicTypeReference

type) { - return setParameter( parameter, val, session.getTypeConfiguration().getBasicTypeRegistry().resolve( type ) ); - } - - @Override - public

QueryImplementor setParameter(QueryParameter

parameter, P value, TemporalType temporalType) { - locateBinding( parameter ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(String name, Object value, TemporalType temporalType) { - locateBinding( name ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(int position, Object value, TemporalType temporalType) { - locateBinding( position ).setBindValue( value, temporalType ); - return this; - } - - @Override - public

QueryImplementor setParameterList(QueryParameter

parameter, Collection

values) { - locateBinding( parameter ).setBindValues( values ); - return this; - } - - @Override - public QueryImplementor setParameterList(String name, @SuppressWarnings("rawtypes") Collection values) { - locateBinding( name ).setBindValues( values ); - return this; - } - - @Override - public QueryImplementor setParameterList(int position, @SuppressWarnings("rawtypes") Collection values) { - locateBinding( position ).setBindValues( values ); - return this; - } - - @Override - public

QueryImplementor setParameterList(String name, Collection values, AllowableParameterType

type) { - this.

locateBinding( name ).setBindValues( values, type ); - return this; - } - - @Override - public

QueryImplementor setParameterList(int position, Collection values, AllowableParameterType

type) { - this.

locateBinding( position ).setBindValues( values, type ); - return this; - } - - @Override - public QueryImplementor setParameterList(String name, Object[] values) { - locateBinding( name ).setBindValues( Arrays.asList( values ) ); - return this; - } - - @Override - public QueryImplementor setParameterList(int position, Object[] values) { - locateBinding( position ).setBindValues( Arrays.asList( values ) ); - return this; - } - - @Override @SuppressWarnings({"rawtypes", "unchecked"}) - public QueryImplementor setParameterList(String name, Object[] values, AllowableParameterType type) { - locateBinding( name ).setBindValues( Arrays.asList( values ), type ); - return this; - } - - @Override @SuppressWarnings({"rawtypes", "unchecked"}) - public QueryImplementor setParameterList(int position, Object[] values, AllowableParameterType type) { - locateBinding( position ).setBindValues( Arrays.asList( values ), type ); - return this; - } - - @Override - public

QueryImplementor setParameterList(String name, Collection values, Class

javaType) { - final JavaType

javaDescriptor = getSession().getFactory() - .getTypeConfiguration() - .getJavaTypeDescriptorRegistry() - .getDescriptor( javaType ); - if ( javaDescriptor == null ) { - setParameterList( name, values ); - } - else { - final AllowableParameterType

paramType; - final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); - if ( basicType != null ) { - paramType = basicType; - } - else { - final ManagedDomainType

managedDomainType = getSession().getFactory() - .getRuntimeMetamodels() - .getJpaMetamodel() - .managedType( javaType ); - if ( managedDomainType != null ) { - paramType = managedDomainType; - } - else { - throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); - } - } - - setParameterList( name, values, paramType ); - } - - return this; - } - - @Override - public

QueryImplementor setParameterList(int position, Collection values, Class

javaType) { - final JavaType

javaDescriptor = getSession().getFactory() - .getTypeConfiguration() - .getJavaTypeDescriptorRegistry() - .getDescriptor( javaType ); - if ( javaDescriptor == null ) { - setParameterList( position, values ); - } - else { - final AllowableParameterType

paramType; - final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); - if ( basicType != null ) { - paramType = basicType; - } - else { - final ManagedDomainType

managedDomainType = getSession().getFactory() - .getRuntimeMetamodels() - .getJpaMetamodel() - .managedType( javaType ); - if ( managedDomainType != null ) { - paramType = managedDomainType; - } - else { - throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); - } - } - - setParameterList( position, values, paramType ); - } - - return this; - } - - @Override - public QueryImplementor setParameter(Parameter param, Calendar value, TemporalType temporalType) { - locateBinding( param ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(Parameter param, Date value, TemporalType temporalType) { - locateBinding( param ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(String name, Calendar value, TemporalType temporalType) { - locateBinding( name ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(String name, Date value, TemporalType temporalType) { - locateBinding( name ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(int position, Calendar value, TemporalType temporalType) { - locateBinding( position ).setBindValue( value, temporalType ); - return this; - } - - @Override - public QueryImplementor setParameter(int position, Date value, TemporalType temporalType) { - locateBinding( position ).setBindValue( value, temporalType ); - return this; - } - @Override public T getParameterValue(Parameter param) { QueryLogging.QUERY_LOGGER.tracef( "#getParameterValue(%s)", param ); @@ -1336,6 +895,643 @@ public abstract class AbstractQuery implements QueryImplementor { } } + @Override + public boolean isBound(Parameter param) { + getSession().checkOpen(); + + final QueryParameterImplementor qp = getParameterMetadata().resolve( param ); + return qp != null && getQueryParameterBindings().isBound( qp ); + } + + @SuppressWarnings( {"WeakerAccess", "unchecked", "rawtypes"} ) + protected

QueryParameterBinding

locateBinding(Parameter

parameter) { + if ( parameter instanceof QueryParameterImplementor ) { + return locateBinding( (QueryParameterImplementor) parameter ); + } + else if ( parameter.getName() != null ) { + return locateBinding( parameter.getName() ); + } + else if ( parameter.getPosition() != null ) { + return locateBinding( parameter.getPosition() ); + } + + throw getSession().getExceptionConverter().convert( + new IllegalArgumentException( "Could not resolve binding for given parameter reference [" + parameter + "]" ) + ); + } + + @SuppressWarnings("WeakerAccess") + protected

QueryParameterBinding

locateBinding(QueryParameterImplementor

parameter) { + getSession().checkOpen(); + return getQueryParameterBindings().getBinding( parameter ); + } + + @SuppressWarnings( {"WeakerAccess"} ) + protected

QueryParameterBinding

locateBinding(String name) { + getSession().checkOpen(); + return getQueryParameterBindings().getBinding( name ); + } + + @SuppressWarnings( {"WeakerAccess"} ) + protected

QueryParameterBinding

locateBinding(int position) { + getSession().checkOpen(); + return getQueryParameterBindings().getBinding( position ); + } + + + + + + + + + + + + + + + + @Override + public QueryImplementor setParameter(String name, Object value) { + if ( value instanceof TypedParameterValue ) { + @SuppressWarnings("unchecked") + final TypedParameterValue typedValue = (TypedParameterValue) value; + final AllowableParameterType type = typedValue.getType(); + if ( type != null ) { + return setParameter( name, typedValue.getValue(), type ); + } + else { + return setParameter( name, typedValue.getValue(), typedValue.getTypeReference() ); + } + } + + final QueryParameterImplementor param = getParameterMetadata().getQueryParameter( name ); + + if ( param == null ) { + throw new IllegalArgumentException( "Named parameter [" + name + "] is not registered with this procedure call" ); + } + + if ( param.allowsMultiValuedBinding() ) { + final AllowableParameterType hibernateType = param.getHibernateType(); + if ( hibernateType == null || isInstance( hibernateType, value ) ) { + if ( value instanceof Collection ) { + //noinspection rawtypes + setParameterList( name, (Collection) value ); + } + } + } + + locateBinding( name ).setBindValue( value, resolveJdbcParameterTypeIfNecessary() ); + + return this; + } + + private boolean isInstance(AllowableParameterType parameterType, Object value) { + final SqmExpressable sqmExpressable = parameterType.resolveExpressable( session.getFactory() ); + assert sqmExpressable != null; + + return sqmExpressable.getExpressableJavaTypeDescriptor().isInstance( value ); + } + + @Override + public

QueryImplementor setParameter(String name, P value, Class

javaType) { + final JavaType

javaDescriptor = getSession().getFactory() + .getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( javaType ); + if ( javaDescriptor == null ) { + setParameter( name, value ); + } + else { + final AllowableParameterType

paramType; + final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + if ( basicType != null ) { + paramType = basicType; + } + else { + final ManagedDomainType

managedDomainType = getSession().getFactory() + .getRuntimeMetamodels() + .getJpaMetamodel() + .managedType( javaType ); + if ( managedDomainType != null ) { + paramType = managedDomainType; + } + else { + throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); + } + } + + setParameter( name, value, paramType ); + } + + return this; + } + + @Override + public

QueryImplementor setParameter(String name, P value, AllowableParameterType

type) { + this.

locateBinding( name ).setBindValue( value, type ); + return this; + } + + @Override + public QueryImplementor setParameter(String name, Instant value, TemporalType temporalType) { + this.locateBinding( name ).setBindValue( value, temporalType ); + return this; + } + + @Override + public QueryImplementor setParameter(int position, Object value) { + if ( value instanceof TypedParameterValue ) { + @SuppressWarnings("unchecked") + final TypedParameterValue typedValue = (TypedParameterValue) value; + final AllowableParameterType type = typedValue.getType(); + if ( type != null ) { + return setParameter( position, typedValue.getValue(), type ); + } + else { + return setParameter( position, typedValue.getValue(), typedValue.getTypeReference() ); + } + } + + final QueryParameterImplementor param = getParameterMetadata().getQueryParameter( position ); + + if ( param == null ) { + throw new IllegalArgumentException( "Positional parameter [" + position + "] is not registered with this procedure call" ); + } + + if ( param.allowsMultiValuedBinding() ) { + final AllowableParameterType hibernateType = param.getHibernateType(); + if ( hibernateType == null || isInstance( hibernateType, value ) ) { + if ( value instanceof Collection ) { + //noinspection rawtypes,unchecked + setParameterList( param, (Collection) value ); + } + } + } + + locateBinding( position ).setBindValue( value, resolveJdbcParameterTypeIfNecessary() ); + return this; + } + + @Override + public

QueryImplementor setParameter(int position, P value, Class

javaType) { + final JavaType

javaDescriptor = getSession().getFactory() + .getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( javaType ); + if ( javaDescriptor == null ) { + setParameter( position, value ); + } + else { + final AllowableParameterType

paramType; + final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + if ( basicType != null ) { + paramType = basicType; + } + else { + final ManagedDomainType

managedDomainType = getSession().getFactory() + .getRuntimeMetamodels() + .getJpaMetamodel() + .managedType( javaType ); + if ( managedDomainType != null ) { + paramType = managedDomainType; + } + else { + throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); + } + } + + setParameter( position, value, paramType ); + } + + return this; + } + + @Override + public

QueryImplementor setParameter(int position, P value, AllowableParameterType

type) { + this.

locateBinding( position ).setBindValue( value, type ); + return this; + } + + @Override + public QueryImplementor setParameter(int position, Instant value, TemporalType temporalType) { + this.locateBinding( position ).setBindValue( value, temporalType ); + return this; + } + + + + @Override + public

QueryImplementor setParameter(QueryParameter

parameter, P value) { + locateBinding( parameter ).setBindValue( value, resolveJdbcParameterTypeIfNecessary() ); + return this; + } + + @Override + public

QueryImplementor setParameter(QueryParameter

parameter, P value, Class

javaType) { + final JavaType

javaDescriptor = getSession().getFactory() + .getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( javaType ); + if ( javaDescriptor == null ) { + setParameter( parameter, value ); + } + else { + final AllowableParameterType

paramType; + final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + if ( basicType != null ) { + paramType = basicType; + } + else { + final ManagedDomainType

managedDomainType = getSession().getFactory() + .getRuntimeMetamodels() + .getJpaMetamodel() + .managedType( javaType ); + if ( managedDomainType != null ) { + paramType = managedDomainType; + } + else { + throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); + } + } + + setParameter( parameter, value, paramType ); + } + + return this; + } + + @Override + public

QueryImplementor setParameter(QueryParameter

parameter, P value, AllowableParameterType

type) { + locateBinding( parameter ).setBindValue( value, type ); + return this; + } + + + @Override + public

QueryImplementor setParameter(Parameter

parameter, P value) { + if ( value instanceof TypedParameterValue ) { + @SuppressWarnings("unchecked") + final TypedParameterValue

typedValue = (TypedParameterValue

) value; + final AllowableParameterType

type = typedValue.getType(); + if ( type != null ) { + setParameter( parameter, typedValue.getValue(), type ); + } + else { + setParameter( parameter, typedValue.getValue(), typedValue.getTypeReference() ); + } + } + else { + locateBinding( parameter ).setBindValue( value, resolveJdbcParameterTypeIfNecessary() ); + } + + return this; + } + + private

void setParameter(Parameter

parameter, P value, AllowableParameterType

type) { + if ( parameter instanceof QueryParameter ) { + setParameter( (QueryParameter

) parameter, value, type ); + } + else if ( value == null ) { + locateBinding( parameter ).setBindValue( null, type ); + } + else if ( value instanceof Collection ) { + //TODO: this looks wrong to me: how can value be both a P and a (Collection

)? + locateBinding( parameter ).setBindValues( (Collection

) value ); + } + else { + locateBinding( parameter ).setBindValue( value, type ); + } + } + + + + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Parameter list + + @Override + public QueryImplementor setParameterList(String name, @SuppressWarnings("rawtypes") Collection values) { + locateBinding( name ).setBindValues( values ); + return this; + } + + public

QueryImplementor setParameterList(String name, Collection values, Class

javaType) { + final JavaType

javaDescriptor = getSession().getFactory() + .getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( javaType ); + if ( javaDescriptor == null ) { + setParameterList( name, values ); + } + else { + final AllowableParameterType

paramType; + final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + if ( basicType != null ) { + paramType = basicType; + } + else { + final ManagedDomainType

managedDomainType = getSession().getFactory() + .getRuntimeMetamodels() + .getJpaMetamodel() + .managedType( javaType ); + if ( managedDomainType != null ) { + paramType = managedDomainType; + } + else { + throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); + } + } + + setParameterList( name, values, paramType ); + } + + return this; + } + + + @Override + public

QueryImplementor setParameterList(String name, Collection values, AllowableParameterType

type) { + this.

locateBinding( name ).setBindValues( values, type ); + return this; + } + + @Override + public QueryImplementor setParameterList(String name, Object[] values) { + locateBinding( name ).setBindValues( Arrays.asList( values ) ); + return this; + } + + @Override + public

QueryImplementor setParameterList(String name, P[] values, Class

javaType) { + final JavaType

javaDescriptor = getSession().getFactory() + .getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( javaType ); + if ( javaDescriptor == null ) { + setParameterList( name, values ); + } + else { + final AllowableParameterType

paramType; + final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + if ( basicType != null ) { + paramType = basicType; + } + else { + final ManagedDomainType

managedDomainType = getSession().getFactory() + .getRuntimeMetamodels() + .getJpaMetamodel() + .managedType( javaType ); + if ( managedDomainType != null ) { + paramType = managedDomainType; + } + else { + throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); + } + } + + setParameterList( name, values, paramType ); + } + + return this; + } + + public

QueryImplementor setParameterList(String name, P[] values, AllowableParameterType

type) { + this.

locateBinding( name ).setBindValues( Arrays.asList( values ), type ); + return this; + } + + @Override + public QueryImplementor setParameterList(int position, @SuppressWarnings("rawtypes") Collection values) { + locateBinding( position ).setBindValues( values ); + return this; + } + + @Override + public

QueryImplementor setParameterList(int position, Collection values, Class

javaType) { + final JavaType

javaDescriptor = getSession().getFactory() + .getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( javaType ); + if ( javaDescriptor == null ) { + setParameterList( position, values ); + } + else { + final AllowableParameterType

paramType; + final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + if ( basicType != null ) { + paramType = basicType; + } + else { + final ManagedDomainType

managedDomainType = getSession().getFactory() + .getRuntimeMetamodels() + .getJpaMetamodel() + .managedType( javaType ); + if ( managedDomainType != null ) { + paramType = managedDomainType; + } + else { + throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); + } + } + + setParameterList( position, values, paramType ); + } + + return this; + } + + @Override + public

QueryImplementor setParameterList(int position, Collection values, AllowableParameterType

type) { + this.

locateBinding( position ).setBindValues( values, type ); + return this; + } + + @Override + public QueryImplementor setParameterList(int position, Object[] values) { + locateBinding( position ).setBindValues( Arrays.asList( values ) ); + return this; + } + + @Override + public

QueryImplementor setParameterList(int position, P[] values, Class

javaType) { + final JavaType

javaDescriptor = getSession().getFactory() + .getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( javaType ); + if ( javaDescriptor == null ) { + setParameterList( position, values ); + } + else { + final AllowableParameterType

paramType; + final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + if ( basicType != null ) { + paramType = basicType; + } + else { + final ManagedDomainType

managedDomainType = getSession().getFactory() + .getRuntimeMetamodels() + .getJpaMetamodel() + .managedType( javaType ); + if ( managedDomainType != null ) { + paramType = managedDomainType; + } + else { + throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); + } + } + + setParameterList( position, values, paramType ); + } + + return this; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public

QueryImplementor setParameterList(int position, P[] values, AllowableParameterType

type) { + locateBinding( position ).setBindValues( Arrays.asList( values ), (AllowableParameterType) type ); + return this; + } + + + + + + + + + @Override + public

QueryImplementor setParameterList(QueryParameter

parameter, Collection values) { + locateBinding( parameter ).setBindValues( values ); + return this; + } + + @Override + public

QueryImplementor setParameterList(QueryParameter

parameter, Collection values, Class

javaType) { + final JavaType

javaDescriptor = getSession().getFactory() + .getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( javaType ); + if ( javaDescriptor == null ) { + setParameterList( parameter, values ); + } + else { + final AllowableParameterType

paramType; + final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + if ( basicType != null ) { + paramType = basicType; + } + else { + final ManagedDomainType

managedDomainType = getSession().getFactory() + .getRuntimeMetamodels() + .getJpaMetamodel() + .managedType( javaType ); + if ( managedDomainType != null ) { + paramType = managedDomainType; + } + else { + throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); + } + } + + setParameterList( parameter, values, paramType ); + } + + return this; + } + + @Override + public

QueryImplementor setParameterList(QueryParameter

parameter, Collection values, AllowableParameterType

type) { + locateBinding( parameter ).setBindValues( values, type ); + return this; + } + + @Override + public

QueryImplementor setParameterList(QueryParameter

parameter, P[] values) { + locateBinding( parameter ).setBindValues( values == null ? null : Arrays.asList( values ) ); + return this; + } + + @Override + public

QueryImplementor setParameterList(QueryParameter

parameter, P[] values, Class

javaType) { + final JavaType

javaDescriptor = getSession().getFactory() + .getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( javaType ); + if ( javaDescriptor == null ) { + setParameterList( parameter, values ); + } + else { + final AllowableParameterType

paramType; + final BasicType

basicType = getSession().getFactory().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + if ( basicType != null ) { + paramType = basicType; + } + else { + final ManagedDomainType

managedDomainType = getSession().getFactory() + .getRuntimeMetamodels() + .getJpaMetamodel() + .managedType( javaType ); + if ( managedDomainType != null ) { + paramType = managedDomainType; + } + else { + throw new HibernateException( "Unable to determine AllowableParameterType : " + javaType.getName() ); + } + } + + setParameterList( parameter, values, paramType ); + } + + return this; + } + + + @Override + public

QueryImplementor setParameterList(QueryParameter

parameter, P[] values, AllowableParameterType

type) { + locateBinding( parameter ).setBindValues( Arrays.asList( values ), type ); + return this; + } + + + @Override + public QueryImplementor setParameter(Parameter param, Calendar value, TemporalType temporalType) { + locateBinding( param ).setBindValue( value, temporalType ); + return this; + } + + @Override + public QueryImplementor setParameter(Parameter param, Date value, TemporalType temporalType) { + locateBinding( param ).setBindValue( value, temporalType ); + return this; + } + + @Override + public QueryImplementor setParameter(String name, Calendar value, TemporalType temporalType) { + locateBinding( name ).setBindValue( value, temporalType ); + return this; + } + + @Override + public QueryImplementor setParameter(String name, Date value, TemporalType temporalType) { + locateBinding( name ).setBindValue( value, temporalType ); + return this; + } + + @Override + public QueryImplementor setParameter(int position, Calendar value, TemporalType temporalType) { + locateBinding( position ).setBindValue( value, temporalType ); + return this; + } + + @Override + public QueryImplementor setParameter(int position, Date value, TemporalType temporalType) { + locateBinding( position ).setBindValue( value, temporalType ); + return this; + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryImplementor.java index 6d63f320a2..39bdb8aa3a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryImplementor.java @@ -7,11 +7,21 @@ package org.hibernate.query.spi; import java.io.Serializable; +import java.time.Instant; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.Map; import org.hibernate.Incubating; import org.hibernate.ScrollMode; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.Query; +import org.hibernate.query.QueryParameter; + +import jakarta.persistence.Parameter; +import jakarta.persistence.TemporalType; /** * @author Steve Ebersole @@ -34,4 +44,119 @@ public interface QueryImplementor extends Query { @Override ScrollableResultsImplementor scroll(ScrollMode scrollMode); + + + @Override + QueryImplementor setParameter(String name, Object value); + + @Override +

QueryImplementor setParameter(String name, P value, Class

type); + + @Override +

QueryImplementor setParameter(String name, P value, AllowableParameterType

type); + + @Override + QueryImplementor setParameter(String name, Instant value, TemporalType temporalType); + + @Override + QueryImplementor setParameter(String name, Calendar value, TemporalType temporalType); + + @Override + QueryImplementor setParameter(String name, Date value, TemporalType temporalType); + + @Override + QueryImplementor setParameter(int position, Object value); + + @Override +

QueryImplementor setParameter(int position, P value, Class

type); + + @Override +

QueryImplementor setParameter(int position, P value, AllowableParameterType

type); + + @Override + QueryImplementor setParameter(int position, Instant value, TemporalType temporalType); + + @Override + QueryImplementor setParameter(int position, Date value, TemporalType temporalType); + + @Override + QueryImplementor setParameter(int position, Calendar value, TemporalType temporalType); + + @Override + QueryImplementor setParameter(QueryParameter parameter, T value); + + @Override +

QueryImplementor setParameter(QueryParameter

parameter, P value, Class

type); + + @Override +

QueryImplementor setParameter(QueryParameter

parameter, P val, AllowableParameterType

type); + + @Override + QueryImplementor setParameter(Parameter param, T value); + + @Override + QueryImplementor setParameter(Parameter param, Calendar value, TemporalType temporalType); + + @Override + QueryImplementor setParameter(Parameter param, Date value, TemporalType temporalType); + + @Override + QueryImplementor setParameterList(String name, Collection values); + + @Override +

QueryImplementor setParameterList(String name, Collection values, Class

javaType); + + @Override +

QueryImplementor setParameterList(String name, Collection values, AllowableParameterType

type); + + @Override + QueryImplementor setParameterList(String name, Object[] values); + + @Override +

QueryImplementor setParameterList(String name, P[] values, Class

javaType); + + @Override +

QueryImplementor setParameterList(String name, P[] values, AllowableParameterType

type); + + @Override + QueryImplementor setParameterList(int position, Collection values); + + @Override +

QueryImplementor setParameterList(int position, Collection values, Class

javaType); + + @Override +

QueryImplementor setParameterList(int position, Collection values, AllowableParameterType

type); + + @Override + QueryImplementor setParameterList(int position, Object[] values); + + @Override +

QueryImplementor setParameterList(int position, P[] values, Class

javaType); + + @Override +

QueryImplementor setParameterList(int position, P[] values, AllowableParameterType

type); + + @Override +

QueryImplementor setParameterList(QueryParameter

parameter, Collection values); + + @Override +

QueryImplementor setParameterList(QueryParameter

parameter, Collection values, Class

javaType); + + @Override +

QueryImplementor setParameterList(QueryParameter

parameter, Collection values, AllowableParameterType

type); + + @Override +

QueryImplementor setParameterList(QueryParameter

parameter, P[] values); + + @Override +

QueryImplementor setParameterList(QueryParameter

parameter, P[] values, Class

javaType); + + @Override +

QueryImplementor setParameterList(QueryParameter

parameter, P[] values, AllowableParameterType

type); + + @Override + QueryImplementor setProperties(Object bean); + + @Override + QueryImplementor setProperties(Map bean); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBinding.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBinding.java index b1883e04bd..74dc85db3d 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBinding.java @@ -11,7 +11,7 @@ import jakarta.persistence.TemporalType; import org.hibernate.Incubating; import org.hibernate.metamodel.mapping.MappingModelExpressable; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.type.spi.TypeConfiguration; /** diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java index daa717c9db..631d760348 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.spi; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.type.spi.TypeConfiguration; /** diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingValidator.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingValidator.java index 8b8a284553..1bef01ff84 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingValidator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingValidator.java @@ -9,12 +9,15 @@ package org.hibernate.query.spi; import java.util.Calendar; import java.util.Collection; import java.util.Date; -import jakarta.persistence.TemporalType; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.query.AllowableParameterType; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter; import org.hibernate.type.descriptor.java.JavaType; +import jakarta.persistence.TemporalType; + /** * @author Andrea Boriero */ @@ -25,49 +28,61 @@ public class QueryParameterBindingValidator { private QueryParameterBindingValidator() { } - public void validate(AllowableParameterType paramType, Object bind) { - validate( paramType, bind, null ); + public void validate(AllowableParameterType paramType, Object bind, SessionFactoryImplementor sessionFactory) { + validate( paramType, bind, null, sessionFactory ); } - public void validate(AllowableParameterType paramType, Object bind, TemporalType temporalType) { + public void validate( + AllowableParameterType paramType, + Object bind, + TemporalType temporalPrecision, + SessionFactoryImplementor sessionFactory) { if ( bind == null || paramType == null ) { // nothing we can check return; } if ( paramType instanceof AttributeConverterTypeAdapter ) { - final AttributeConverterTypeAdapter converterTypeAdapter = (AttributeConverterTypeAdapter) paramType; - final JavaType domainJtd = converterTypeAdapter.getDomainJtd(); + final AttributeConverterTypeAdapter converterTypeAdapter = (AttributeConverterTypeAdapter) paramType; + final JavaType domainJtd = converterTypeAdapter.getDomainJtd(); if ( domainJtd.getJavaTypeClass().isInstance( bind ) ) { return; } } - final Class parameterType = paramType.getExpressableJavaTypeDescriptor().getJavaTypeClass(); - if ( parameterType == null ) { + final Class parameterJavaType; + if ( paramType.getBindableJavaType() != null ) { + parameterJavaType = paramType.getBindableJavaType(); + } + else { + final SqmExpressable sqmExpressable = paramType.resolveExpressable( sessionFactory ); + parameterJavaType = sqmExpressable.getBindableJavaType(); + } + + if ( parameterJavaType == null ) { // nothing we can check return; } - if ( Collection.class.isInstance( bind ) && !Collection.class.isAssignableFrom( parameterType ) ) { + if ( bind instanceof Collection && !Collection.class.isAssignableFrom( parameterJavaType ) ) { // we have a collection passed in where we are expecting a non-collection. // NOTE : this can happen in Hibernate's notion of "parameter list" binding // NOTE2 : the case of a collection value and an expected collection (if that can even happen) // will fall through to the main check. - validateCollectionValuedParameterBinding( parameterType, (Collection) bind, temporalType ); + validateCollectionValuedParameterBinding( parameterJavaType, (Collection) bind, temporalPrecision ); } else if ( bind.getClass().isArray() ) { - validateArrayValuedParameterBinding( parameterType, bind, temporalType ); + validateArrayValuedParameterBinding( parameterJavaType, bind, temporalPrecision ); } else { - if ( !isValidBindValue( parameterType, bind, temporalType ) ) { + if ( !isValidBindValue( parameterJavaType, bind, temporalPrecision ) ) { throw new IllegalArgumentException( String.format( "Parameter value [%s] did not match expected type [%s (%s)]", bind, - parameterType.getName(), - extractName( temporalType ) + parameterJavaType.getName(), + extractName( temporalPrecision ) ) ); } @@ -79,8 +94,8 @@ public class QueryParameterBindingValidator { } private void validateCollectionValuedParameterBinding( - Class parameterType, - Collection value, + Class parameterType, + Collection value, TemporalType temporalType) { // validate the elements... for ( Object element : value ) { @@ -97,7 +112,7 @@ public class QueryParameterBindingValidator { } } - private static boolean isValidBindValue(Class expectedType, Object value, TemporalType temporalType) { + private static boolean isValidBindValue(Class expectedType, Object value, TemporalType temporalType) { if ( expectedType.isPrimitive() ) { if ( expectedType == boolean.class ) { return value instanceof Boolean; @@ -137,16 +152,14 @@ public class QueryParameterBindingValidator { final boolean bindIsTemporal = value instanceof Date || value instanceof Calendar; - if ( parameterDeclarationIsTemporal && bindIsTemporal ) { - return true; - } + return parameterDeclarationIsTemporal && bindIsTemporal; } return false; } private void validateArrayValuedParameterBinding( - Class parameterType, + Class parameterType, Object value, TemporalType temporalType) { if ( !parameterType.isArray() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterImplementor.java index 854d1b7fbc..292aa7f9de 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterImplementor.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.spi; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.QueryParameter; import org.hibernate.query.named.NamedQueryMemento; @@ -16,7 +16,7 @@ import org.hibernate.query.named.NamedQueryMemento; public interface QueryParameterImplementor extends QueryParameter { void disallowMultiValuedBinding(); - void applyAnticipatedType(AllowableParameterType type); + void applyAnticipatedType(AllowableParameterType type); NamedQueryMemento.ParameterMemento toMemento(); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterListBinding.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterListBinding.java index 8b3b69426c..dd4a70fad6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterListBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterListBinding.java @@ -10,7 +10,7 @@ import java.util.Collection; import jakarta.persistence.TemporalType; import org.hibernate.Incubating; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.internal.QueryParameterBindingsImpl; import org.hibernate.type.Type; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index d843ff2107..c6ecb9bf23 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -8,9 +8,6 @@ package org.hibernate.query.sql.internal; import java.io.Serializable; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.OffsetDateTime; -import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Collection; import java.util.Collections; @@ -44,8 +41,8 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jpa.internal.util.LockModeTypeHelper; import org.hibernate.jpa.spi.NativeQueryTupleTransformer; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.BasicDomainType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.NativeQuery; import org.hibernate.query.ParameterMetadata; import org.hibernate.query.Query; @@ -1208,17 +1205,8 @@ public class NativeQueryImpl return true; } - @Override - public

NativeQueryImplementor setParameter(QueryParameter

parameter, P value) { - super.setParameter( parameter, value ); - return this; - } - @Override - public

NativeQueryImplementor setParameter(Parameter

parameter, P value) { - super.setParameter( parameter, value ); - return this; - } + @Override public NativeQueryImplementor setParameter(String name, Object value) { @@ -1227,199 +1215,14 @@ public class NativeQueryImpl } @Override - public NativeQueryImplementor setParameter(int position, Object value) { - super.setParameter( position, value ); - return this; - } - -// @Override -// @SuppressWarnings("unchecked") -// public NativeQueryImplementor setParameter(QueryParameter parameter, Object value, Type type) { -// super.setParameter( parameter, value, type ); -// return this; -// } -// -// @Override -// public NativeQueryImplementor setParameter(String name, Object value, Type type) { -// super.setParameter( name, value, type ); -// return this; -// } -// -// @Override -// public NativeQueryImplementor setParameter(int position, Object value, Type type) { -// super.setParameter( position, value, type ); -// return this; -// } - - @Override - public

NativeQueryImplementor setParameter(QueryParameter

parameter, P value, TemporalType temporalType) { - super.setParameter( parameter, value, temporalType ); + public

NativeQueryImplementor setParameter(String name, P value, Class

javaType) { + super.setParameter( name, value, javaType ); return this; } @Override - public NativeQueryImplementor setParameter(String name, Object value, TemporalType temporalType) { - super.setParameter( name, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(int position, Object value, TemporalType temporalType) { - super.setParameter( position, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(Parameter param, Instant value, TemporalType temporalType) { - super.setParameter( param, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(Parameter param, LocalDateTime value, TemporalType temporalType) { - super.setParameter( param, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(Parameter param, ZonedDateTime value, TemporalType temporalType) { - super.setParameter( param, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(Parameter param, OffsetDateTime value, TemporalType temporalType) { - super.setParameter( param, value, temporalType ); - return this; - } -// -// @Override -// public NativeQueryImplementor setParameterList(int position, Collection values, Type type) { -// return setParameterList( position, values, ( AllowableParameterType) type ); -// } - - @Override - public

NativeQueryImplementor setParameterList(String name, Collection values, AllowableParameterType

type) { - super.setParameterList( name, values, type ); - return this; - } - - @Override - public

NativeQueryImplementor setParameterList( - int position, Collection values, - AllowableParameterType

type) { - super.setParameterList( position, values, type ); - return this; - } - - @Override - public NativeQueryImplementor setParameterList( - String name, Object[] values, - @SuppressWarnings("rawtypes") AllowableParameterType type) { - super.setParameterList( name, values, type ); - return this; - } - - @Override - public NativeQueryImplementor setParameterList( - int position, Object[] values, - @SuppressWarnings("rawtypes") AllowableParameterType type) { - super.setParameterList( position, values, type ); - return this; - } - -// @Override -// public NativeQueryImplementor setParameterList(int position, Object[] values, Type type) { -// return null; -// } - - @Override - public NativeQueryImplementor setParameter(String name, Instant value, TemporalType temporalType) { - super.setParameter( name, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(String name, LocalDateTime value, TemporalType temporalType) { - super.setParameter( name, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(String name, ZonedDateTime value, TemporalType temporalType) { - super.setParameter( name, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(String name, OffsetDateTime value, TemporalType temporalType) { - super.setParameter( name, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(int position, Instant value, TemporalType temporalType) { - super.setParameter( position, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(int position, LocalDateTime value, TemporalType temporalType) { - super.setParameter( position, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(int position, ZonedDateTime value, TemporalType temporalType) { - super.setParameter( position, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(int position, OffsetDateTime value, TemporalType temporalType) { - super.setParameter( position, value, temporalType ); - return this; - } - - @Override - public

NativeQueryImplementor setParameterList(QueryParameter

parameter, Collection

values) { - super.setParameterList( parameter, values ); - return this; - } - - @Override - public NativeQueryImplementor setParameterList(String name, @SuppressWarnings("rawtypes") Collection values) { - super.setParameterList( name, values ); - return this; - } - -// @Override -// public NativeQueryImplementor setParameterList(String name, Collection values, Type type) { -// super.setParameterList( name, values, type ); -// return this; -// } -// -// @Override -// public NativeQueryImplementor setParameterList(String name, Object[] values, Type type) { -// super.setParameterList( name, values, type ); -// return this; -// } - - @Override - public NativeQueryImplementor setParameterList(String name, Object[] values) { - super.setParameterList( name, values ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(Parameter param, Calendar value, TemporalType temporalType) { - super.setParameter( param, value, temporalType ); - return this; - } - - @Override - public NativeQueryImplementor setParameter(Parameter param, Date value, TemporalType temporalType) { - super.setParameter( param, value, temporalType ); + public

NativeQueryImplementor setParameter(String name, P value, AllowableParameterType

type) { + super.setParameter( name, value, type ); return this; } @@ -1429,12 +1232,42 @@ public class NativeQueryImpl return this; } + @Override + public NativeQueryImplementor setParameter(String name, Instant value, TemporalType temporalType) { + super.setParameter( name, value, temporalType ); + return this; + } + @Override public NativeQueryImplementor setParameter(String name, Date value, TemporalType temporalType) { super.setParameter( name, value, temporalType ); return this; } + @Override + public NativeQueryImplementor setParameter(int position, Object value) { + super.setParameter( position, value ); + return this; + } + + @Override + public

NativeQueryImplementor setParameter(int position, P value, Class

javaType) { + super.setParameter( position, value, javaType ); + return this; + } + + @Override + public

NativeQueryImplementor setParameter(int position, P value, AllowableParameterType

type) { + super.setParameter( position, value, type ); + return this; + } + + @Override + public NativeQueryImplementor setParameter(int position, Instant value, TemporalType temporalType) { + super.setParameter( position, value, temporalType ); + return this; + } + @Override public NativeQueryImplementor setParameter(int position, Calendar value, TemporalType temporalType) { super.setParameter( position, value, temporalType ); @@ -1447,9 +1280,160 @@ public class NativeQueryImpl return this; } - @Override @SuppressWarnings("deprecation") - public NativeQueryImplementor setResultTransformer(ResultTransformer transformer) { - super.setResultTransformer( transformer ); + @Override + public

NativeQueryImplementor setParameter(QueryParameter

parameter, P value) { + super.setParameter( parameter, value ); + return this; + } + + @Override + public

NativeQueryImplementor setParameter(QueryParameter

parameter, P value, Class

javaType) { + super.setParameter( parameter, value, javaType ); + return this; + } + + @Override + public

NativeQueryImplementor setParameter(QueryParameter

parameter, P value, AllowableParameterType

type) { + super.setParameter( parameter, value, type ); + return this; + } + + @Override + public

NativeQueryImplementor setParameter(Parameter

parameter, P value) { + super.setParameter( parameter, value ); + return this; + } + + @Override + public NativeQueryImplementor setParameter(Parameter param, Calendar value, TemporalType temporalType) { + super.setParameter( param, value, temporalType ); + return this; + } + + @Override + public NativeQueryImplementor setParameter(Parameter param, Date value, TemporalType temporalType) { + super.setParameter( param, value, temporalType ); + return this; + } + + + + + + + + + + @Override + public NativeQueryImplementor setParameterList(String name, @SuppressWarnings("rawtypes") Collection values) { + super.setParameterList( name, values ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(String name, Collection values, Class

javaType) { + super.setParameterList( name, values, javaType ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(String name, Collection values, AllowableParameterType

type) { + super.setParameterList( name, values, type ); + return this; + } + + @Override + public NativeQueryImplementor setParameterList(String name, Object[] values) { + super.setParameterList( name, values ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(String name, P[] values, Class

javaType) { + super.setParameterList( name, values, javaType ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(String name, P[] values, AllowableParameterType

type) { + super.setParameterList( name, values, type ); + return this; + } + + + + + @Override + public NativeQueryImplementor setParameterList(int position, @SuppressWarnings("rawtypes") Collection values) { + super.setParameterList( position, values ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(int position, Collection values, Class

javaType) { + super.setParameterList( position, values, javaType ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(int position, Collection values, AllowableParameterType

type) { + super.setParameterList( position, values, type ); + return this; + } + + @Override + public NativeQueryImplementor setParameterList(int position, Object[] values) { + super.setParameterList( position, values ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(int position, P[] values, Class

javaType) { + super.setParameterList( position, values, javaType ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(int position, P[] values, AllowableParameterType

type) { + super.setParameterList( position, values, type ); + return this; + } + + + + @Override + public

NativeQueryImplementor setParameterList(QueryParameter

parameter, Collection values) { + super.setParameterList( parameter, values ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(QueryParameter

parameter, Collection values, Class

javaType) { + super.setParameterList( parameter, values, javaType ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(QueryParameter

parameter, Collection values, AllowableParameterType

type) { + super.setParameterList( parameter, values, type ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(QueryParameter

parameter, P[] values) { + super.setParameterList( parameter, values ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(QueryParameter

parameter, P[] values, Class

javaType) { + super.setParameterList( parameter, values, javaType ); + return this; + } + + @Override + public

NativeQueryImplementor setParameterList(QueryParameter

parameter, P[] values, AllowableParameterType

type) { + super.setParameterList( parameter, values, type ); return this; } @@ -1465,6 +1449,23 @@ public class NativeQueryImpl return this; } + + + + + + + + + + + + @Override @SuppressWarnings("deprecation") + public NativeQueryImplementor setResultTransformer(ResultTransformer transformer) { + super.setResultTransformer( transformer ); + return this; + } + @Override public NativeQueryImplementor setMaxResults(int maxResult) { super.setMaxResults( maxResult ); @@ -1477,65 +1478,6 @@ public class NativeQueryImpl return this; } - @Override - public

NativeQueryImplementor setParameter(QueryParameter

parameter, P value, AllowableParameterType

type) { - super.setParameter( parameter, value, type ); - return this; - } - - @Override - public

NativeQueryImplementor setParameter(String name, P value, AllowableParameterType

type) { - super.setParameter( name, value, type ); - return this; - } - - @Override - public

NativeQueryImplementor setParameter(int position, P value, AllowableParameterType

type) { - super.setParameter( position, value, type ); - return this; - } - - @Override - public

NativeQueryImplementor setParameter(String name, P value, BasicTypeReference

type) { - super.setParameter( name, value, type ); - return this; - } - - @Override - public

NativeQueryImplementor setParameter(int position, P value, BasicTypeReference

type) { - super.setParameter( position, value, type ); - return this; - } - - @Override - public

NativeQueryImplementor setParameter(QueryParameter

parameter, P val, BasicTypeReference

type) { - super.setParameter( parameter, val, type ); - return this; - } - - @Override - public NativeQueryImplementor setParameterList(int position, @SuppressWarnings("rawtypes") Collection values) { - super.setParameterList( position, values ); - return this; - } - - @Override - public NativeQueryImplementor setParameterList(int position, Object[] values) { - super.setParameterList( position, values ); - return this; - } - - @Override - public

NativeQueryImplementor setParameterList(String name, Collection values, Class

javaType) { - super.setParameterList( name, values, javaType ); - return this; - } - - @Override - public

NativeQueryImplementor setParameterList(int position, Collection values, Class

javaType) { - super.setParameterList( position, values, javaType ); - return this; - } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java index 271aab0f26..88562ec675 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java @@ -7,19 +7,10 @@ package org.hibernate.query.sql.spi; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.OffsetDateTime; -import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.Map; -import jakarta.persistence.AttributeConverter; -import jakarta.persistence.FlushModeType; -import jakarta.persistence.LockModeType; -import jakarta.persistence.Parameter; -import jakarta.persistence.TemporalType; -import jakarta.persistence.metamodel.SingularAttribute; import org.hibernate.CacheMode; import org.hibernate.FlushMode; @@ -27,8 +18,8 @@ import org.hibernate.Incubating; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.MappingException; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.BasicDomainType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.NativeQuery; import org.hibernate.query.QueryParameter; import org.hibernate.query.ResultListTransformer; @@ -36,7 +27,13 @@ import org.hibernate.query.TupleTransformer; import org.hibernate.query.named.NameableQuery; import org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard; import org.hibernate.query.spi.QueryImplementor; -import org.hibernate.type.BasicTypeReference; + +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.FlushModeType; +import jakarta.persistence.LockModeType; +import jakarta.persistence.Parameter; +import jakarta.persistence.TemporalType; +import jakarta.persistence.metamodel.SingularAttribute; /** * @author Steve Ebersole @@ -193,191 +190,125 @@ public interface NativeQueryImplementor extends QueryImplementor, NativeQu NativeQueryImplementor addQueryHint(String hint); @Override -

NativeQueryImplementor setParameter(QueryParameter

parameter, P val); + NativeQueryImplementor setTupleTransformer(@SuppressWarnings("rawtypes") TupleTransformer transformer); @Override -

NativeQueryImplementor setParameter(Parameter

param, P value); + NativeQueryImplementor setResultListTransformer(ResultListTransformer transformer); @Override NativeQueryImplementor setParameter(String name, Object val); -// @Override -// default

NativeQueryImplementor setParameter(QueryParameter

parameter, P val, Type type) { -// return setParameter( parameter, val, (AllowableParameterType) type ); -// } + @Override +

NativeQueryImplementor setParameter(String name, P val, AllowableParameterType

type); @Override -

NativeQueryImplementor setParameter(QueryParameter

parameter, P val, AllowableParameterType

type); +

NativeQueryImplementor setParameter(String name, P val, Class

type); + + @Override + NativeQueryImplementor setParameter(String name, Instant value, TemporalType temporalType); + + @Override + NativeQueryImplementor setParameter(String name, Date value, TemporalType temporalType); + + @Override + NativeQueryImplementor setParameter(String name, Calendar value, TemporalType temporalType); @Override NativeQueryImplementor setParameter(int position, Object val); -// @Override -// default NativeQueryImplementor setParameter(String name, Object val, Type type) { -// return setParameter( name, val, (AllowableParameterType) type ); -// } - @Override -

NativeQueryImplementor setParameter(String name, P val, AllowableParameterType

type); - -// @Override -// default NativeQueryImplementor setParameter(int position, Object val, Type type) { -// return setParameter( position, val, (AllowableParameterType) type ); -// } +

NativeQueryImplementor setParameter(int position, P val, Class

type); @Override

NativeQueryImplementor setParameter(int position, P val, AllowableParameterType

type); @Override -

NativeQueryImplementor setParameter(String name, P val, BasicTypeReference

type); + NativeQueryImplementor setParameter(int position, Instant value, TemporalType temporalType); @Override -

NativeQueryImplementor setParameter(int position, P val, BasicTypeReference

type); + NativeQueryImplementor setParameter(int position, Date value, TemporalType temporalType); @Override -

NativeQueryImplementor setParameter(QueryParameter

parameter, P val, BasicTypeReference

type); + NativeQueryImplementor setParameter(int position, Calendar value, TemporalType temporalType); @Override -

NativeQueryImplementor setParameter( - QueryParameter

parameter, - P val, - TemporalType temporalType); +

NativeQueryImplementor setParameter(QueryParameter

parameter, P val); @Override - NativeQueryImplementor setParameter(String name, Object val, TemporalType temporalType); +

NativeQueryImplementor setParameter(QueryParameter

parameter, P val, Class

type); @Override - NativeQueryImplementor setParameter(int position, Object val, TemporalType temporalType); +

NativeQueryImplementor setParameter(QueryParameter

parameter, P val, AllowableParameterType

type); @Override -

NativeQueryImplementor setParameterList( - QueryParameter

parameter, - Collection

values); +

NativeQueryImplementor setParameter(Parameter

param, P value); + + @Override + NativeQueryImplementor setParameter(Parameter param, Date value, TemporalType temporalType); + + @Override + NativeQueryImplementor setParameter(Parameter param, Calendar value, TemporalType temporalType); @Override NativeQueryImplementor setParameterList(String name, @SuppressWarnings("rawtypes") Collection values); -// @Override -// default NativeQueryImplementor setParameterList(String name, Collection values, Type type) { -// return setParameterList( name, values, (AllowableParameterType) type ); -// } + @Override +

NativeQueryImplementor setParameterList(String name, Collection values, Class

type); @Override

NativeQueryImplementor setParameterList(String name, Collection values, AllowableParameterType

type); -// -// @Override -// default NativeQueryImplementor setParameterList(String name, Object[] values, Type type) { -// return setParameterList( name, values, (AllowableParameterType) type ); -// } - - @Override - NativeQueryImplementor setParameterList(String name, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type); @Override NativeQueryImplementor setParameterList(String name, Object[] values); + @Override +

NativeQueryImplementor setParameterList(String name, P[] values, Class

type); + + @Override +

NativeQueryImplementor setParameterList(String name, P[] values, AllowableParameterType

type); + + @Override + NativeQueryImplementor setParameterList(int position, @SuppressWarnings("rawtypes") Collection values); + + @Override +

NativeQueryImplementor setParameterList(int position, Collection values, Class

type); + + @Override +

NativeQueryImplementor setParameterList(int position, Collection values, AllowableParameterType

type); + + @Override + NativeQueryImplementor setParameterList(int position, Object[] values); + + @Override +

NativeQueryImplementor setParameterList(int position, P[] values, Class

javaType); + + @Override +

NativeQueryImplementor setParameterList(int position, P[] values, AllowableParameterType

type); + + + @Override +

NativeQueryImplementor setParameterList(QueryParameter

parameter, Collection values); + + @Override +

NativeQueryImplementor setParameterList(QueryParameter

parameter, Collection values, Class

javaType); + + @Override +

NativeQueryImplementor setParameterList(QueryParameter

parameter, Collection values, AllowableParameterType

type); + + @Override +

NativeQueryImplementor setParameterList(QueryParameter

parameter, P[] values); + + @Override +

NativeQueryImplementor setParameterList(QueryParameter

parameter, P[] values, Class

javaType); + + @Override +

NativeQueryImplementor setParameterList(QueryParameter

parameter, P[] values, AllowableParameterType

type); + @Override NativeQueryImplementor setProperties(Object bean); @Override NativeQueryImplementor setProperties(@SuppressWarnings("rawtypes") Map bean); - @Override - NativeQueryImplementor setParameter( - Parameter param, - Date value, - TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter( - Parameter param, - Calendar value, - TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(String name, Date value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter( - String name, - Calendar value, - TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter( - int position, - Calendar value, - TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(int position, Date value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(String name, Instant value, TemporalType temporalType); - - @Override - NativeQueryImplementor setTupleTransformer(@SuppressWarnings("rawtypes") TupleTransformer transformer); - - @Override - NativeQueryImplementor setResultListTransformer(ResultListTransformer transformer); - - @Override - NativeQueryImplementor setParameter(int position, Instant value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(Parameter param, Instant value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(String name, LocalDateTime value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(int position, LocalDateTime value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(Parameter param, LocalDateTime value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(String name, ZonedDateTime value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(int position, ZonedDateTime value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(Parameter param, ZonedDateTime value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(String name, OffsetDateTime value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(int position, OffsetDateTime value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameter(Parameter param, OffsetDateTime value, TemporalType temporalType); - - @Override - NativeQueryImplementor setParameterList(int position, @SuppressWarnings("rawtypes") Collection values); - - @Override -

NativeQueryImplementor setParameterList(String name, Collection values, Class

type); - - @Override -

NativeQueryImplementor setParameterList(int position, Collection values, Class

type); - -// @Override -// NativeQueryImplementor setParameterList(int position, Collection values, Type type); - - @Override -

NativeQueryImplementor setParameterList(int position, Collection values, AllowableParameterType

type); - -// @Override -// NativeQueryImplementor setParameterList(int position, Object[] values, Type type); - - @Override - NativeQueryImplementor setParameterList(int position, Object[] values, @SuppressWarnings("rawtypes") AllowableParameterType type); - - @Override - NativeQueryImplementor setParameterList(int position, Object[] values); - - } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java index 32faf8c040..11694c5ddc 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java @@ -16,23 +16,10 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; -import jakarta.persistence.Tuple; -import jakarta.persistence.criteria.CollectionJoin; -import jakarta.persistence.criteria.Expression; -import jakarta.persistence.criteria.Join; -import jakarta.persistence.criteria.ListJoin; -import jakarta.persistence.criteria.MapJoin; -import jakarta.persistence.criteria.Path; -import jakarta.persistence.criteria.Predicate; -import jakarta.persistence.criteria.Root; -import jakarta.persistence.criteria.Selection; -import jakarta.persistence.criteria.SetJoin; -import jakarta.persistence.criteria.Subquery; +import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.query.NullPrecedence; import org.hibernate.query.SortOrder; -import org.hibernate.metamodel.model.domain.DomainType; -import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.query.criteria.HibernateCriteriaBuilder; import org.hibernate.query.criteria.JpaCoalesce; import org.hibernate.query.criteria.JpaCompoundSelection; @@ -50,6 +37,7 @@ import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmSetJoin; import org.hibernate.query.sqm.tree.domain.SqmSingularJoin; import org.hibernate.query.sqm.tree.expression.SqmExpression; +import org.hibernate.query.sqm.tree.expression.SqmFunction; import org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression; import org.hibernate.query.sqm.tree.expression.SqmTuple; import org.hibernate.query.sqm.tree.from.SqmRoot; @@ -61,10 +49,22 @@ import org.hibernate.query.sqm.tree.select.SqmSortSpecification; import org.hibernate.query.sqm.tree.select.SqmSubQuery; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; import org.hibernate.service.ServiceRegistry; -import org.hibernate.query.sqm.tree.expression.SqmFunction; import org.hibernate.type.BasicType; import org.hibernate.type.spi.TypeConfiguration; +import jakarta.persistence.Tuple; +import jakarta.persistence.criteria.CollectionJoin; +import jakarta.persistence.criteria.Expression; +import jakarta.persistence.criteria.Join; +import jakarta.persistence.criteria.ListJoin; +import jakarta.persistence.criteria.MapJoin; +import jakarta.persistence.criteria.Path; +import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Root; +import jakarta.persistence.criteria.Selection; +import jakarta.persistence.criteria.SetJoin; +import jakarta.persistence.criteria.Subquery; + /** * Adapts the JPA CriteriaBuilder to generate SQM nodes. * @@ -84,6 +84,22 @@ public interface NodeBuilder extends HibernateCriteriaBuilder { QueryEngine getQueryEngine(); + SqmTuple tuple( + Class tupleType, + SqmExpression... expressions); + + SqmTuple tuple( + Class tupleType, + List> expressions); + + SqmTuple tuple( + SqmExpressable tupleType, + SqmExpression... expressions); + + SqmTuple tuple( + SqmExpressable tupleType, + List> expressions); + @Override SqmSelectStatement createQuery(); @@ -404,26 +420,6 @@ public interface NodeBuilder extends HibernateCriteriaBuilder { @Override JpaSearchedCase selectCase(); - @Override - SqmTuple tuple( - Class tupleType, - JpaExpression... expressions); - - @Override - SqmTuple tuple( - Class tupleType, - List> expressions); - - @Override - SqmTuple tuple( - DomainType tupleType, - JpaExpression... expressions); - - @Override - SqmTuple tuple( - DomainType tupleType, - List> expressions); - @Override SqmPredicate and(Expression x, Expression y); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmExpressable.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmExpressable.java index 51a7f079c4..dcc5327d34 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmExpressable.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmExpressable.java @@ -6,6 +6,8 @@ */ package org.hibernate.query.sqm; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.type.descriptor.java.JavaType; @@ -17,9 +19,14 @@ import org.hibernate.type.descriptor.java.JavaType; * * @author Steve Ebersole */ -public interface SqmExpressable { +public interface SqmExpressable extends AllowableParameterType { /** * The Java type descriptor for this expressable */ JavaType getExpressableJavaTypeDescriptor(); + + @Override + default SqmExpressable resolveExpressable(SessionFactoryImplementor sessionFactory) { + return this; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmFunctionDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmFunctionDescriptor.java index 651eb78b4f..ccaa0e06c3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmFunctionDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmFunctionDescriptor.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.sqm.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.produce.function.ArgumentsValidator; import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java index 01d22e0c05..0e4630b051 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.sqm.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.produce.function.ArgumentsValidator; import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/JdbcEscapeFunctionDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/JdbcEscapeFunctionDescriptor.java index c496ed69e2..409852d16f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/JdbcEscapeFunctionDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/JdbcEscapeFunctionDescriptor.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.sqm.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.type.spi.TypeConfiguration; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/MultipatternSqmFunctionDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/MultipatternSqmFunctionDescriptor.java index e37af963ea..2f6494b47f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/MultipatternSqmFunctionDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/MultipatternSqmFunctionDescriptor.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.sqm.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.produce.function.ArgumentTypesValidator; import org.hibernate.query.sqm.produce.function.FunctionParameterType; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingAggregateFunctionSqlAstExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingAggregateFunctionSqlAstExpression.java index ad34b7328a..6c2d1ee8a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingAggregateFunctionSqlAstExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingAggregateFunctionSqlAstExpression.java @@ -10,7 +10,7 @@ import java.util.List; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.JdbcMappingContainer; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.tree.SqlAstNode; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java index bd5a6dfee5..3fe57a968b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingFunctionSqlAstExpression.java @@ -17,8 +17,7 @@ import org.hibernate.mapping.Table; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.JdbcMappingContainer; import org.hibernate.metamodel.mapping.SqlExpressable; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; -import org.hibernate.query.SemanticException; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.sql.ast.SqlAstTranslator; import org.hibernate.sql.ast.SqlAstWalker; @@ -33,7 +32,6 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.basic.BasicResult; import org.hibernate.sql.results.internal.SqlSelectionImpl; -import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.spi.TypeConfiguration; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmAggregateFunction.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmAggregateFunction.java index 7a87f89b99..677ac7b25b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmAggregateFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmAggregateFunction.java @@ -8,7 +8,7 @@ package org.hibernate.query.sqm.function; import java.util.List; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.produce.function.ArgumentsValidator; import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmFunction.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmFunction.java index 1f18b4d002..78c4c05fa1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmFunction.java @@ -12,7 +12,7 @@ import java.util.List; import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.BasicValuedMapping; import org.hibernate.metamodel.mapping.MappingModelExpressable; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.produce.function.ArgumentsValidator; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionDescriptor.java index a4489c8795..bc48a0d831 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunctionDescriptor.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.sqm.function; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.produce.function.ArgumentsValidator; import org.hibernate.query.sqm.tree.SqmTypedNode; 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 fccc340fe4..2a4baad2e3 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 @@ -23,40 +23,26 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Supplier; -import jakarta.persistence.Tuple; -import jakarta.persistence.criteria.CollectionJoin; -import jakarta.persistence.criteria.CriteriaQuery; -import jakarta.persistence.criteria.Expression; -import jakarta.persistence.criteria.Join; -import jakarta.persistence.criteria.ListJoin; -import jakarta.persistence.criteria.MapJoin; -import jakarta.persistence.criteria.Path; -import jakarta.persistence.criteria.Predicate; -import jakarta.persistence.criteria.Root; -import jakarta.persistence.criteria.Selection; -import jakarta.persistence.criteria.SetJoin; -import jakarta.persistence.criteria.Subquery; import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.QueryException; import org.hibernate.SessionFactory; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.SessionFactoryRegistry; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.query.NullPrecedence; -import org.hibernate.QueryException; -import org.hibernate.query.SetOperator; -import org.hibernate.query.SortOrder; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; +import org.hibernate.query.AllowableFunctionReturnType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.BinaryArithmeticOperator; import org.hibernate.query.ComparisonOperator; -import org.hibernate.query.SemanticException; +import org.hibernate.query.NullPrecedence; +import org.hibernate.query.SetOperator; +import org.hibernate.query.SortOrder; import org.hibernate.query.TrimSpec; import org.hibernate.query.UnaryArithmeticOperator; import org.hibernate.query.criteria.JpaCoalesce; @@ -131,8 +117,22 @@ import org.hibernate.service.ServiceRegistry; import org.hibernate.type.BasicType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.java.JavaType; -import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.spi.TypeConfiguration; + +import jakarta.persistence.Tuple; +import jakarta.persistence.criteria.CollectionJoin; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Expression; +import jakarta.persistence.criteria.Join; +import jakarta.persistence.criteria.ListJoin; +import jakarta.persistence.criteria.MapJoin; +import jakarta.persistence.criteria.Path; +import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Root; +import jakarta.persistence.criteria.Selection; +import jakarta.persistence.criteria.SetJoin; +import jakarta.persistence.criteria.Subquery; + import static java.util.Arrays.asList; import static org.hibernate.query.internal.QueryHelper.highestPrecedenceType; @@ -436,37 +436,33 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, } @Override - public SqmTuple tuple(Class tupleType, JpaExpression... expressions) { - //noinspection unchecked - return tuple( tupleType, (List>) (List) asList( expressions ) ); + public SqmTuple tuple(Class tupleType, SqmExpression... expressions) { + return tuple( tupleType, asList( expressions ) ); } @Override - public SqmTuple tuple(Class tupleType, List> expressions) { + public SqmTuple tuple(Class tupleType, List> expressions) { final TypeConfiguration typeConfiguration = getTypeConfiguration(); @SuppressWarnings("unchecked") - final List> sqmExpressions = (List>) (List) expressions; - final DomainType domainType; + final List> sqmExpressions = (List>) expressions; + final SqmExpressable expressableType; if ( tupleType == null || tupleType == Object[].class ) { //noinspection unchecked - domainType = (DomainType) typeConfiguration.resolveTupleType( sqmExpressions ); + expressableType = (DomainType) typeConfiguration.resolveTupleType( sqmExpressions ); } else { - domainType = typeConfiguration.getSessionFactory().getMetamodel().embeddable( tupleType ); + expressableType = typeConfiguration.getSessionFactory().getMetamodel().embeddable( tupleType ); } - return tuple( domainType, sqmExpressions ); + return tuple( expressableType, sqmExpressions ); } @Override - public SqmTuple tuple(DomainType tupleType, JpaExpression... expressions) { - //noinspection unchecked - return tuple( tupleType, (List>) (List) asList( expressions ) ); + public SqmTuple tuple(SqmExpressable tupleType, SqmExpression... expressions) { + return tuple( tupleType, asList( expressions ) ); } @Override - public SqmTuple tuple(DomainType tupleType, List> expressions) { - @SuppressWarnings("unchecked") - final List> sqmExpressions = (List>) (List) expressions; + public SqmTuple tuple(SqmExpressable tupleType, List> sqmExpressions) { if ( tupleType == null ) { //noinspection unchecked tupleType = (DomainType) getTypeConfiguration().resolveTupleType( sqmExpressions ); @@ -921,11 +917,14 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return new SqmLiteralNull<>( this ); } - return new SqmLiteral<>( - value, - queryEngine.getTypeConfiguration().getSessionFactory().resolveParameterBindType( value ), - this - ); + final AllowableParameterType valueParamType = queryEngine.getTypeConfiguration() + .getSessionFactory() + .resolveParameterBindType( value ); + final SqmExpressable sqmExpressable = valueParamType == null + ? null + : valueParamType.resolveExpressable( getTypeConfiguration().getSessionFactory() ); + + return new SqmLiteral<>( value, sqmExpressable, this ); } @Override @@ -970,7 +969,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return new SqmLiteralNull<>( sqmExpressable, this ); } - class MultiValueParameterType implements AllowableParameterType { + class MultiValueParameterType implements SqmExpressable { private final JavaType javaTypeDescriptor; public MultiValueParameterType(Class type) { @@ -986,12 +985,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, } @Override - public PersistenceType getPersistenceType() { - return PersistenceType.BASIC; - } - - @Override - public Class getJavaType() { + public Class getBindableJavaType() { return javaTypeDescriptor.getJavaTypeClass(); } } @@ -1049,7 +1043,6 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, } @Override - @SuppressWarnings({ "unchecked" }) public SqmExpression concat(Expression x, String y) { final SqmExpression xSqmExpression = (SqmExpression) x; final SqmExpression ySqmExpression = value( y, xSqmExpression ); @@ -1063,7 +1056,6 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, } @Override - @SuppressWarnings({ "unchecked" }) public SqmExpression concat(String x, Expression y) { final SqmExpression ySqmExpression = (SqmExpression) y; final SqmExpression xSqmExpression = value( x, ySqmExpression ); @@ -1077,7 +1069,6 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, } @Override - @SuppressWarnings({ "unchecked" }) public SqmExpression concat(String x, String y) { final SqmExpression xSqmExpression = value( x ); final SqmExpression ySqmExpression = value( y, xSqmExpression ); @@ -1450,7 +1441,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return (AllowableParameterType) typeInferenceSource; } - if ( typeInferenceSource.getNodeType() instanceof AllowableParameterType ) { + if ( typeInferenceSource.getNodeType() != null ) { //noinspection unchecked return (AllowableParameterType) typeInferenceSource.getNodeType(); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/FunctionReturnTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/FunctionReturnTypeResolver.java index b45f345e9d..5ca3b426f5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/FunctionReturnTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/FunctionReturnTypeResolver.java @@ -7,7 +7,7 @@ package org.hibernate.query.sqm.produce.function; import org.hibernate.metamodel.mapping.BasicValuedMapping; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.type.spi.TypeConfiguration; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java index a6e7300608..d40be593b7 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java @@ -15,7 +15,7 @@ import org.hibernate.QueryException; import org.hibernate.metamodel.mapping.BasicValuedMapping; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.JdbcMappingContainer; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.sql.ast.tree.SqlAstNode; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 77f64a9ddd..9515726801 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -83,48 +83,29 @@ import org.hibernate.metamodel.mapping.internal.EntityCollectionPart; import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping; import org.hibernate.metamodel.mapping.ordering.OrderByFragment; import org.hibernate.metamodel.model.convert.spi.BasicValueConverter; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.PluralPersistentAttribute; import org.hibernate.metamodel.model.domain.internal.CompositeSqmPathSource; import org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath; import org.hibernate.persister.entity.AbstractEntityPersister; -import org.hibernate.query.FetchClauseType; -import org.hibernate.query.SortOrder; -import org.hibernate.query.criteria.JpaPath; -import org.hibernate.query.internal.QueryHelper; -import org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression; -import org.hibernate.query.sqm.produce.function.internal.PatternRenderer; -import org.hibernate.query.sqm.tree.SqmJoinType; -import org.hibernate.query.sqm.tree.domain.SqmCorrelatedRootJoin; -import org.hibernate.query.sqm.tree.domain.SqmCorrelation; -import org.hibernate.query.sqm.tree.domain.SqmPluralPartJoin; -import org.hibernate.query.sqm.tree.expression.*; -import org.hibernate.query.sqm.tree.insert.SqmInsertStatement; -import org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression; -import org.hibernate.query.sqm.tree.domain.SqmTreatedRoot; -import org.hibernate.sql.ast.tree.expression.Over; -import org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression; -import org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup; -import org.hibernate.sql.ast.tree.from.NamedTableReference; -import org.hibernate.sql.ast.tree.from.PluralTableGroup; -import org.hibernate.sql.ast.tree.from.QueryPartTableGroup; -import org.hibernate.sql.ast.tree.from.QueryPartTableReference; -import org.hibernate.sql.ast.tree.from.TableReference; -import org.hibernate.sql.exec.internal.VersionTypeSeedParameterSpecification; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Joinable; +import org.hibernate.query.AllowableFunctionReturnType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.BinaryArithmeticOperator; import org.hibernate.query.CastType; import org.hibernate.query.ComparisonOperator; import org.hibernate.query.DynamicInstantiationNature; +import org.hibernate.query.FetchClauseType; import org.hibernate.query.NavigablePath; import org.hibernate.query.QueryLogging; import org.hibernate.query.SemanticException; +import org.hibernate.query.SortOrder; import org.hibernate.query.TemporalUnit; import org.hibernate.query.UnaryArithmeticOperator; +import org.hibernate.query.criteria.JpaPath; +import org.hibernate.query.internal.QueryHelper; import org.hibernate.query.spi.QueryOptions; import org.hibernate.query.spi.QueryParameterBinding; import org.hibernate.query.spi.QueryParameterBindings; @@ -135,8 +116,10 @@ import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.sqm.SqmQuerySource; import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; import org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression; +import org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression; import org.hibernate.query.sqm.internal.DomainParameterXref; import org.hibernate.query.sqm.internal.SqmMappingModelHelper; +import org.hibernate.query.sqm.produce.function.internal.PatternRenderer; import org.hibernate.query.sqm.spi.BaseSemanticQueryWalker; import org.hibernate.query.sqm.sql.internal.BasicValuedPathInterpretation; import org.hibernate.query.sqm.sql.internal.DiscriminatedAssociationPathInterpretation; @@ -152,6 +135,7 @@ import org.hibernate.query.sqm.sql.internal.SqmMapEntryResult; import org.hibernate.query.sqm.sql.internal.SqmParameterInterpretation; import org.hibernate.query.sqm.sql.internal.SqmPathInterpretation; import org.hibernate.query.sqm.sql.internal.TypeHelper; +import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.query.sqm.tree.cte.SqmCteContainer; @@ -164,6 +148,8 @@ import org.hibernate.query.sqm.tree.domain.AbstractSqmSpecificPluralPartPath; import org.hibernate.query.sqm.tree.domain.NonAggregatedCompositeSimplePath; import org.hibernate.query.sqm.tree.domain.SqmAnyValuedSimplePath; import org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath; +import org.hibernate.query.sqm.tree.domain.SqmCorrelatedRootJoin; +import org.hibernate.query.sqm.tree.domain.SqmCorrelation; import org.hibernate.query.sqm.tree.domain.SqmEmbeddedValuedSimplePath; import org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath; import org.hibernate.query.sqm.tree.domain.SqmIndexedCollectionAccessPath; @@ -171,8 +157,45 @@ import org.hibernate.query.sqm.tree.domain.SqmMapEntryReference; import org.hibernate.query.sqm.tree.domain.SqmElementAggregateFunction; import org.hibernate.query.sqm.tree.domain.SqmIndexAggregateFunction; import org.hibernate.query.sqm.tree.domain.SqmPath; +import org.hibernate.query.sqm.tree.domain.SqmPluralPartJoin; import org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath; import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; +import org.hibernate.query.sqm.tree.domain.SqmTreatedRoot; +import org.hibernate.query.sqm.tree.expression.Conversion; +import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter; +import org.hibernate.query.sqm.tree.expression.SqmAliasedNodeRef; +import org.hibernate.query.sqm.tree.expression.SqmAny; +import org.hibernate.query.sqm.tree.expression.SqmBinaryArithmetic; +import org.hibernate.query.sqm.tree.expression.SqmByUnit; +import org.hibernate.query.sqm.tree.expression.SqmCaseSearched; +import org.hibernate.query.sqm.tree.expression.SqmCaseSimple; +import org.hibernate.query.sqm.tree.expression.SqmCastTarget; +import org.hibernate.query.sqm.tree.expression.SqmCollation; +import org.hibernate.query.sqm.tree.expression.SqmCollectionSize; +import org.hibernate.query.sqm.tree.expression.SqmDistinct; +import org.hibernate.query.sqm.tree.expression.SqmDurationUnit; +import org.hibernate.query.sqm.tree.expression.SqmEnumLiteral; +import org.hibernate.query.sqm.tree.expression.SqmEvery; +import org.hibernate.query.sqm.tree.expression.SqmExpression; +import org.hibernate.query.sqm.tree.expression.SqmExtractUnit; +import org.hibernate.query.sqm.tree.expression.SqmFieldLiteral; +import org.hibernate.query.sqm.tree.expression.SqmFormat; +import org.hibernate.query.sqm.tree.expression.SqmFunction; +import org.hibernate.query.sqm.tree.expression.SqmJpaCriteriaParameterWrapper; +import org.hibernate.query.sqm.tree.expression.SqmLiteral; +import org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType; +import org.hibernate.query.sqm.tree.expression.SqmLiteralNull; +import org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression; +import org.hibernate.query.sqm.tree.expression.SqmNamedParameter; +import org.hibernate.query.sqm.tree.expression.SqmParameter; +import org.hibernate.query.sqm.tree.expression.SqmParameterizedEntityType; +import org.hibernate.query.sqm.tree.expression.SqmPositionalParameter; +import org.hibernate.query.sqm.tree.expression.SqmStar; +import org.hibernate.query.sqm.tree.expression.SqmSummarization; +import org.hibernate.query.sqm.tree.expression.SqmToDuration; +import org.hibernate.query.sqm.tree.expression.SqmTrimSpecification; +import org.hibernate.query.sqm.tree.expression.SqmTuple; +import org.hibernate.query.sqm.tree.expression.SqmUnaryOperation; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmCrossJoin; import org.hibernate.query.sqm.tree.from.SqmEntityJoin; @@ -181,6 +204,7 @@ import org.hibernate.query.sqm.tree.from.SqmFromClause; import org.hibernate.query.sqm.tree.from.SqmJoin; import org.hibernate.query.sqm.tree.from.SqmRoot; import org.hibernate.query.sqm.tree.insert.SqmInsertSelectStatement; +import org.hibernate.query.sqm.tree.insert.SqmInsertStatement; import org.hibernate.query.sqm.tree.insert.SqmInsertValuesStatement; import org.hibernate.query.sqm.tree.insert.SqmValues; import org.hibernate.query.sqm.tree.predicate.SqmAndPredicate; @@ -256,19 +280,28 @@ import org.hibernate.sql.ast.tree.expression.ExtractUnit; import org.hibernate.sql.ast.tree.expression.Format; import org.hibernate.sql.ast.tree.expression.JdbcLiteral; import org.hibernate.sql.ast.tree.expression.JdbcParameter; +import org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression; +import org.hibernate.sql.ast.tree.expression.Over; import org.hibernate.sql.ast.tree.expression.QueryLiteral; import org.hibernate.sql.ast.tree.expression.SelfRenderingExpression; +import org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression; import org.hibernate.sql.ast.tree.expression.SqlSelectionExpression; import org.hibernate.sql.ast.tree.expression.SqlTuple; import org.hibernate.sql.ast.tree.expression.Star; import org.hibernate.sql.ast.tree.expression.Summarization; import org.hibernate.sql.ast.tree.expression.TrimSpecification; import org.hibernate.sql.ast.tree.expression.UnaryOperation; +import org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup; import org.hibernate.sql.ast.tree.from.CorrelatedTableGroup; import org.hibernate.sql.ast.tree.from.LazyTableGroup; +import org.hibernate.sql.ast.tree.from.NamedTableReference; +import org.hibernate.sql.ast.tree.from.PluralTableGroup; +import org.hibernate.sql.ast.tree.from.QueryPartTableGroup; +import org.hibernate.sql.ast.tree.from.QueryPartTableReference; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableGroupJoin; import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer; +import org.hibernate.sql.ast.tree.from.TableReference; import org.hibernate.sql.ast.tree.from.VirtualTableGroup; import org.hibernate.sql.ast.tree.insert.InsertStatement; import org.hibernate.sql.ast.tree.insert.Values; @@ -297,6 +330,7 @@ import org.hibernate.sql.ast.tree.update.Assignment; import org.hibernate.sql.ast.tree.update.UpdateStatement; import org.hibernate.sql.exec.internal.JdbcParameterImpl; import org.hibernate.sql.exec.internal.JdbcParametersImpl; +import org.hibernate.sql.exec.internal.VersionTypeSeedParameterSpecification; import org.hibernate.sql.exec.spi.ExecutionContext; import org.hibernate.sql.exec.spi.JdbcParameterBindings; import org.hibernate.sql.exec.spi.JdbcParameters; @@ -4350,24 +4384,26 @@ public abstract class BaseSqmToSqlAstConverter extends Base } } - AllowableParameterType parameterSqmType = binding.getBindType(); - if ( parameterSqmType == null ) { - parameterSqmType = queryParameter.getHibernateType(); - if ( parameterSqmType == null ) { - parameterSqmType = sqmParameter.getAnticipatedType(); + AllowableParameterType paramType = binding.getBindType(); + if ( paramType == null ) { + paramType = queryParameter.getHibernateType(); + if ( paramType == null ) { + paramType = sqmParameter.getAnticipatedType(); } } - if ( parameterSqmType == null ) { + if ( paramType == null ) { // Default to the Object type return basicType( Object.class ); } - else if ( parameterSqmType instanceof MappingModelExpressable && parameterSqmType.getJavaType() == Object.class ) { - return (MappingModelExpressable) parameterSqmType; + else if ( paramType instanceof MappingModelExpressable && paramType.getBindableJavaType() == Object.class ) { + return (MappingModelExpressable) paramType; } - if ( parameterSqmType instanceof SqmPath ) { - final SqmPath sqmPath = (SqmPath) parameterSqmType; + final SqmExpressable paramSqmType = paramType.resolveExpressable( creationContext.getSessionFactory() ); + + if ( paramSqmType instanceof SqmPath ) { + final SqmPath sqmPath = (SqmPath) paramSqmType; final NavigablePath navigablePath = sqmPath.getNavigablePath(); if ( navigablePath.getParent() != null ) { final TableGroup tableGroup = getFromClauseAccess().getTableGroup( navigablePath.getParent() ); @@ -4380,11 +4416,11 @@ public abstract class BaseSqmToSqlAstConverter extends Base return getFromClauseAccess().getTableGroup( navigablePath ).getModelPart(); } - if ( parameterSqmType instanceof BasicValuedMapping ) { - return (BasicValuedMapping) parameterSqmType; + if ( paramSqmType instanceof BasicValuedMapping ) { + return (BasicValuedMapping) paramSqmType; } - if ( parameterSqmType instanceof CompositeSqmPathSource ) { + if ( paramSqmType instanceof CompositeSqmPathSource ) { // Try to infer the value mapping since the other side apparently is a path source final MappingModelExpressable inferredValueMapping = getInferredValueMapping(); if ( inferredValueMapping != null ) { @@ -4393,15 +4429,14 @@ public abstract class BaseSqmToSqlAstConverter extends Base throw new NotYetImplementedFor6Exception( "Support for embedded-valued parameters not yet implemented" ); } - if ( parameterSqmType instanceof SqmPathSource || parameterSqmType instanceof BasicDomainType ) { + if ( paramSqmType instanceof SqmPathSource || paramSqmType instanceof BasicDomainType ) { // Try to infer the value mapping since the other side apparently is a path source final MappingModelExpressable inferredValueMapping = getInferredValueMapping(); if ( inferredValueMapping != null ) { return inferredValueMapping; } return getTypeConfiguration().getBasicTypeForJavaType( - ( (SqmExpressable) parameterSqmType ).getExpressableJavaTypeDescriptor() - .getJavaTypeClass() + paramSqmType.getExpressableJavaTypeDescriptor().getJavaTypeClass() ); } @@ -4838,7 +4873,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base .findFunctionDescriptor( "timestampdiff" ); } - private T cleanly(Supplier supplier) { + private X cleanly(Supplier supplier) { SqmByUnit byUnit = appliedByUnit; Expression timestamp = adjustedTimestamp; SqmExpressable timestampType = adjustedTimestampType; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmParameterInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmParameterInterpretation.java index 264c6a74bb..c5fa622a8f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmParameterInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmParameterInterpretation.java @@ -9,42 +9,44 @@ package org.hibernate.query.sqm.sql.internal; import java.util.List; import java.util.function.Function; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.DiscriminatedAssociationModelPart; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.EntityValuedModelPart; import org.hibernate.metamodel.mapping.MappingModelExpressable; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.SemanticException; import org.hibernate.query.spi.QueryParameterBinding; import org.hibernate.query.spi.QueryParameterImplementor; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.tree.expression.SqmParameter; import org.hibernate.sql.ast.SqlAstWalker; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.expression.Expression; -import org.hibernate.sql.ast.tree.expression.SqlTuple; import org.hibernate.sql.ast.tree.expression.JdbcParameter; +import org.hibernate.sql.ast.tree.expression.SqlTuple; import org.hibernate.sql.ast.tree.expression.SqlTupleContainer; -import org.hibernate.sql.results.graph.basic.BasicResult; import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultCreationState; +import org.hibernate.sql.results.graph.basic.BasicResult; /** * @author Steve Ebersole */ public class SqmParameterInterpretation implements Expression, DomainResultProducer, SqlTupleContainer { - private final SqmParameter sqmParameter; + private final SqmParameter sqmParameter; private final QueryParameterImplementor queryParameter; - private final MappingModelExpressable valueMapping; - private final Function queryParameterBindingResolver; + private final MappingModelExpressable valueMapping; + private final Function, QueryParameterBinding> queryParameterBindingResolver; private final Expression resolvedExpression; public SqmParameterInterpretation( - SqmParameter sqmParameter, + SqmParameter sqmParameter, QueryParameterImplementor queryParameter, List jdbcParameters, - MappingModelExpressable valueMapping, - Function queryParameterBindingResolver) { + MappingModelExpressable valueMapping, + Function, QueryParameterBinding> queryParameterBindingResolver) { this.sqmParameter = sqmParameter; this.queryParameter = queryParameter; this.queryParameterBindingResolver = queryParameterBindingResolver; @@ -62,7 +64,7 @@ public class SqmParameterInterpretation implements Expression, DomainResultProdu this.resolvedExpression = determineResolvedExpression( jdbcParameters, this.valueMapping ); } - private Expression determineResolvedExpression(List jdbcParameters, MappingModelExpressable valueMapping) { + private Expression determineResolvedExpression(List jdbcParameters, MappingModelExpressable valueMapping) { if ( valueMapping instanceof EmbeddableValuedModelPart || valueMapping instanceof DiscriminatedAssociationModelPart ) { return new SqlTuple( jdbcParameters, valueMapping ); @@ -82,38 +84,39 @@ public class SqmParameterInterpretation implements Expression, DomainResultProdu } @Override - public MappingModelExpressable getExpressionType() { + public MappingModelExpressable getExpressionType() { return valueMapping; } @Override - public DomainResult createDomainResult( + public DomainResult createDomainResult( String resultVariable, DomainResultCreationState creationState) { if ( resolvedExpression instanceof SqlTuple ) { throw new SemanticException( "Composite query parameter cannot be used in select" ); } - AllowableParameterType nodeType = sqmParameter.getNodeType(); + AllowableParameterType nodeType = sqmParameter.getNodeType(); if ( nodeType == null ) { final QueryParameterBinding binding = queryParameterBindingResolver.apply( queryParameter ); nodeType = binding.getBindType(); } + final SessionFactoryImplementor sessionFactory = creationState.getSqlAstCreationState() + .getCreationContext() + .getSessionFactory(); + + final SqmExpressable sqmExpressable = nodeType.resolveExpressable( sessionFactory ); final SqlSelection sqlSelection = creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( resolvedExpression, - nodeType.getExpressableJavaTypeDescriptor(), - creationState.getSqlAstCreationState() - .getCreationContext() - .getSessionFactory() - .getTypeConfiguration() + sqmExpressable.getExpressableJavaTypeDescriptor(), + sessionFactory.getTypeConfiguration() ); - //noinspection unchecked - return new BasicResult( + return new BasicResult<>( sqlSelection.getValuesArrayPosition(), resultVariable, - nodeType.getExpressableJavaTypeDescriptor() + sqmExpressable.getExpressableJavaTypeDescriptor() ); } @@ -134,19 +137,22 @@ public class SqmParameterInterpretation implements Expression, DomainResultProdu throw new SemanticException( "Composite query parameter cannot be used in select" ); } - AllowableParameterType nodeType = sqmParameter.getNodeType(); + AllowableParameterType nodeType = sqmParameter.getNodeType(); if ( nodeType == null ) { final QueryParameterBinding binding = queryParameterBindingResolver.apply( queryParameter ); nodeType = binding.getBindType(); } + final SessionFactoryImplementor sessionFactory = creationState.getSqlAstCreationState() + .getCreationContext() + .getSessionFactory(); + + final SqmExpressable sqmExpressable = nodeType.resolveExpressable( sessionFactory ); + return creationState.getSqlAstCreationState().getSqlExpressionResolver().resolveSqlSelection( resolvedExpression, - nodeType.getExpressableJavaTypeDescriptor(), - creationState.getSqlAstCreationState() - .getCreationContext() - .getSessionFactory() - .getTypeConfiguration() + sqmExpressable.getExpressableJavaTypeDescriptor(), + sessionFactory.getTypeConfiguration() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBasicValuedSimplePath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBasicValuedSimplePath.java index 07184ae8cb..6971c538b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBasicValuedSimplePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBasicValuedSimplePath.java @@ -6,14 +6,15 @@ */ package org.hibernate.query.sqm.tree.domain; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.EntityDomainType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.NavigablePath; import org.hibernate.query.PathException; import org.hibernate.query.SemanticException; import org.hibernate.query.hql.spi.SqmCreationState; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.type.descriptor.java.BasicJavaType; import org.hibernate.type.descriptor.java.JavaType; @@ -23,7 +24,7 @@ import org.hibernate.type.descriptor.java.JavaType; */ public class SqmBasicValuedSimplePath extends AbstractSqmSimplePath - implements AllowableParameterType { + implements AllowableParameterType, SqmExpressable { public SqmBasicValuedSimplePath( NavigablePath navigablePath, SqmPathSource referencedPathSource, @@ -86,19 +87,19 @@ public class SqmBasicValuedSimplePath throw new UnsupportedOperationException( "Basic-value cannot be treated (downcast)" ); } + @Override + public Class getJavaType() { + return getJavaTypeDescriptor().getJavaTypeClass(); + } + @Override public JavaType getExpressableJavaTypeDescriptor() { return getJavaTypeDescriptor(); } @Override - public PersistenceType getPersistenceType() { - return PersistenceType.BASIC; - } - - @Override - public Class getJavaType() { - return getJavaTypeDescriptor().getJavaTypeClass(); + public Class getBindableJavaType() { + return getJavaType(); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEmbeddedValuedSimplePath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEmbeddedValuedSimplePath.java index f3036784c8..a8a1f97bff 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEmbeddedValuedSimplePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEmbeddedValuedSimplePath.java @@ -6,23 +6,24 @@ */ package org.hibernate.query.sqm.tree.domain; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.NavigablePath; import org.hibernate.query.PathException; -import org.hibernate.query.hql.spi.SemanticPathPart; -import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.query.sqm.SqmPathSource; -import org.hibernate.query.sqm.UnknownPathException; -import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.type.descriptor.java.JavaType; /** * @author Steve Ebersole */ -public class SqmEmbeddedValuedSimplePath extends AbstractSqmSimplePath implements AllowableParameterType { +public class SqmEmbeddedValuedSimplePath + extends AbstractSqmSimplePath + implements AllowableParameterType, SqmExpressable { public SqmEmbeddedValuedSimplePath( NavigablePath navigablePath, SqmPathSource referencedPathSource, @@ -76,21 +77,15 @@ public class SqmEmbeddedValuedSimplePath extends AbstractSqmSimplePath imp return getJavaTypeDescriptor(); } - @Override - public PersistenceType getPersistenceType() { - return PersistenceType.EMBEDDABLE; - } - @Override public Class getJavaType() { return getJavaTypeDescriptor().getJavaTypeClass(); } -// @Override -// public DomainResult createDomainResult( -// String resultVariable, -// DomainResultCreationState creationState, -// DomainResultCreationContext creationContext) { -// return new CompositeResultImpl( getNavigablePath(), getReferencedNavigable(), resultVariable, creationState ); -// } + @Override + public Class getBindableJavaType() { + return getJavaType(); + } + + } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEntityValuedSimplePath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEntityValuedSimplePath.java index 29b3ce4e3d..85057a4363 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEntityValuedSimplePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmEntityValuedSimplePath.java @@ -9,11 +9,10 @@ package org.hibernate.query.sqm.tree.domain; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.query.NavigablePath; import org.hibernate.query.PathException; -import org.hibernate.query.hql.spi.SemanticPathPart; -import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.query.sqm.SqmPathSource; -import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmPathSource; /** * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java index 46f992e270..77312e4dd7 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java @@ -11,8 +11,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.function.Consumer; -import jakarta.persistence.criteria.Expression; -import jakarta.persistence.criteria.Predicate; import org.hibernate.query.criteria.JpaSelection; import org.hibernate.query.sqm.NodeBuilder; @@ -21,6 +19,9 @@ import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.tree.select.SqmSelectableNode; import org.hibernate.type.descriptor.java.JavaType; +import jakarta.persistence.criteria.Expression; +import jakarta.persistence.criteria.Predicate; + /** * Represents the reference to a Map attribute's {@link Map.Entry} entries @@ -45,8 +46,7 @@ public class SqmMapEntryReference this.mapPath = mapPath; this.nodeBuilder = nodeBuilder; - //noinspection unchecked - this.mapEntryTypeDescriptor = (JavaType) nodeBuilder.getDomainModel() + this.mapEntryTypeDescriptor = nodeBuilder.getDomainModel() .getTypeConfiguration() .getJavaTypeDescriptorRegistry() .getDescriptor( Map.Entry.class ); @@ -107,6 +107,11 @@ public class SqmMapEntryReference return this; } + @Override + public Class> getBindableJavaType() { + return getNodeType().getBindableJavaType(); + } + @Override public NodeBuilder nodeBuilder() { return nodeBuilder; @@ -156,5 +161,4 @@ public class SqmMapEntryReference public Expression as(Class type) { throw new UnsupportedOperationException( "Whatever JPA" ); } - } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmParameter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmParameter.java index 2ac8f1a055..fb0b084c61 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmParameter.java @@ -6,8 +6,8 @@ */ package org.hibernate.query.sqm.tree.expression; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.metamodel.model.domain.PluralPersistentAttribute; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.internal.QueryHelper; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmExpressable; @@ -22,7 +22,7 @@ public abstract class AbstractSqmParameter extends AbstractSqmExpression i public AbstractSqmParameter( boolean canBeMultiValued, - AllowableParameterType inherentType, + SqmExpressable inherentType, NodeBuilder nodeBuilder) { super( inherentType, nodeBuilder ); this.canBeMultiValued = canBeMultiValued; @@ -36,7 +36,7 @@ public abstract class AbstractSqmParameter extends AbstractSqmExpression i else if ( type instanceof PluralPersistentAttribute ) { type = ( (PluralPersistentAttribute) type ).getElementType(); } - final SqmExpressable oldType = getNodeType(); + final SqmExpressable oldType = getNodeType(); final SqmExpressable newType = QueryHelper.highestPrecedenceType( oldType, type ); if ( newType != null && newType != oldType ) { @@ -59,11 +59,6 @@ public abstract class AbstractSqmParameter extends AbstractSqmExpression i return canBeMultiValued; } - @Override - public AllowableParameterType getNodeType() { - return (AllowableParameterType) super.getNodeType(); - } - @Override public AllowableParameterType getAnticipatedType() { return this.getNodeType(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/JpaCriteriaParameter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/JpaCriteriaParameter.java index c9709096f9..e47f9d1394 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/JpaCriteriaParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/JpaCriteriaParameter.java @@ -7,8 +7,8 @@ package org.hibernate.query.sqm.tree.expression; import org.hibernate.NotYetImplementedFor6Exception; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.procedure.spi.NamedCallableQueryMemento; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.ParameterMetadata; import org.hibernate.query.criteria.JpaParameterExpression; import org.hibernate.query.spi.QueryParameterImplementor; @@ -48,7 +48,7 @@ public class JpaCriteriaParameter AllowableParameterType type, boolean allowsMultiValuedBinding, NodeBuilder nodeBuilder) { - super( type, nodeBuilder ); + super( toSqmType( type, nodeBuilder ), nodeBuilder ); this.name = name; this.value = null; this.allowsMultiValuedBinding = allowsMultiValuedBinding; @@ -60,14 +60,23 @@ public class JpaCriteriaParameter T value, boolean allowsMultiValuedBinding, NodeBuilder nodeBuilder) { - super( type, nodeBuilder ); + super( toSqmType( type, nodeBuilder ), nodeBuilder ); this.name = name; this.value = value; this.allowsMultiValuedBinding = allowsMultiValuedBinding; } - public JpaCriteriaParameter(AllowableParameterType type, T value, NodeBuilder criteriaBuilder) { - super( type, criteriaBuilder ); + private static SqmExpressable toSqmType(AllowableParameterType type, NodeBuilder nodeBuilder) { + if ( type == null ) { + return null; + } + return type.resolveExpressable( + nodeBuilder.getQueryEngine().getTypeConfiguration().getSessionFactory() + ); + } + + public JpaCriteriaParameter(AllowableParameterType type, T value, NodeBuilder nodeBuilder) { + super( toSqmType( type, nodeBuilder ), nodeBuilder ); this.name = null; this.value = value; } @@ -107,14 +116,10 @@ public class JpaCriteriaParameter return getHibernateType(); } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void applyAnticipatedType(AllowableParameterType type) { - super.internalApplyInferableType( type ); - } - - @Override - public AllowableParameterType getNodeType() { - return (AllowableParameterType) super.getNodeType(); + super.internalApplyInferableType( toSqmType( type, nodeBuilder() ) ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/NullSqmExpressable.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/NullSqmExpressable.java new file mode 100644 index 0000000000..89c3285314 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/NullSqmExpressable.java @@ -0,0 +1,30 @@ +/* + * 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.query.sqm.tree.expression; + +import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.type.descriptor.java.JavaType; + +/** + * @author Steve Ebersole + */ +public class NullSqmExpressable implements SqmExpressable { + /** + * Singleton access + */ + public static final NullSqmExpressable NULL_SQM_EXPRESSABLE = new NullSqmExpressable(); + + @Override + public Class getBindableJavaType() { + return null; + } + + @Override + public JavaType getExpressableJavaTypeDescriptor() { + return null; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCastTarget.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCastTarget.java index 4388e55820..67568aa003 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCastTarget.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCastTarget.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.sqm.tree.expression; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SqmExpressable; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmDurationUnit.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmDurationUnit.java index 73d849f4d3..43a3d33e76 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmDurationUnit.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmDurationUnit.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.sqm.tree.expression; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.TemporalUnit; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEnumLiteral.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEnumLiteral.java index 0e69da0a20..78a9cccd26 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEnumLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEnumLiteral.java @@ -46,15 +46,17 @@ public class SqmEnumLiteral> extends AbstractSqmExpression return enumValue; } - public String getEnumValueName() { - return enumValueName; - } - @Override public EnumJavaTypeDescriptor getExpressableJavaTypeDescriptor() { return referencedEnumTypeDescriptor; } + @Override + public Class getBindableJavaType() { + return getJavaTypeDescriptor().getJavaTypeClass(); + } + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // SemanticPathPart @@ -134,5 +136,4 @@ public class SqmEnumLiteral> extends AbstractSqmExpression sb.append( '.' ); sb.append( enumValueName ); } - } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java index 78de8dd349..88ad12dc6c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java @@ -13,7 +13,7 @@ import java.util.function.Consumer; import jakarta.persistence.criteria.Expression; import org.hibernate.annotations.Remove; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.query.criteria.JpaExpression; import org.hibernate.query.spi.QueryEngine; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/LiteralHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpressionHelper.java similarity index 69% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/LiteralHelper.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpressionHelper.java index a7f28be6fa..7170a182ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/LiteralHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpressionHelper.java @@ -13,16 +13,44 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; -import org.hibernate.query.spi.QueryEngine; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.spi.QueryEngine; +import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.type.descriptor.java.JdbcDateJavaTypeDescriptor; import org.hibernate.type.descriptor.java.JdbcTimeJavaTypeDescriptor; import org.hibernate.type.descriptor.java.JdbcTimestampJavaTypeDescriptor; +import org.hibernate.type.spi.TypeConfiguration; /** * @author Steve Ebersole */ -public class LiteralHelper { +public class SqmExpressionHelper { + public static SqmExpressable toSqmType(AllowableParameterType parameterType, SqmCreationState creationState) { + return toSqmType( parameterType, creationState.getCreationContext().getJpaMetamodel().getTypeConfiguration() ); + } + + public static SqmExpressable toSqmType(AllowableParameterType anticipatedType, NodeBuilder nodeBuilder) { + return toSqmType( anticipatedType, nodeBuilder.getTypeConfiguration() ); + } + + public static SqmExpressable toSqmType(AllowableParameterType anticipatedType, TypeConfiguration typeConfiguration) { + return toSqmType( anticipatedType, typeConfiguration.getSessionFactory() ); + } + + public static SqmExpressable toSqmType(AllowableParameterType anticipatedType, SessionFactoryImplementor sessionFactory) { + if ( anticipatedType == null ) { + return null; + } + final SqmExpressable sqmExpressable = anticipatedType.resolveExpressable( sessionFactory ); + assert sqmExpressable != null; + + return sqmExpressable; + + } + public static SqmLiteral timestampLiteralFrom(String literalText, SqmCreationState creationState) { final Timestamp literal = Timestamp.valueOf( LocalDateTime.from( JdbcTimestampJavaTypeDescriptor.LITERAL_FORMATTER.parse( literalText ) ) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExtractUnit.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExtractUnit.java index 99b2598775..b831c1c455 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExtractUnit.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExtractUnit.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.sqm.tree.expression; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.TemporalUnit; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java index 1c2c5c0fd7..f56252d9f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java @@ -12,7 +12,6 @@ import java.math.BigInteger; import java.util.Collection; import java.util.List; import java.util.Locale; -import jakarta.persistence.criteria.Expression; import org.hibernate.QueryException; import org.hibernate.query.SemanticException; @@ -27,6 +26,8 @@ import org.hibernate.query.sqm.tree.predicate.SqmPredicate; import org.hibernate.query.sqm.tree.select.SqmSelectableNode; import org.hibernate.type.descriptor.java.JavaType; +import jakarta.persistence.criteria.Expression; + /** * @author Steve Ebersole */ @@ -77,10 +78,6 @@ public class SqmFieldLiteral implements SqmExpression, SqmExpressable, return value; } - public JavaType getFieldJavaTypeDescriptor() { - return fieldJavaTypeDescriptor; - } - public String getFieldName() { return fieldName; } @@ -96,8 +93,6 @@ public class SqmFieldLiteral implements SqmExpression, SqmExpressable, @Override public void applyInferableType(SqmExpressable type) { - //noinspection unchecked -// this.expressable = (SqmExpressable) type; } @Override @@ -114,6 +109,11 @@ public class SqmFieldLiteral implements SqmExpression, SqmExpressable, return getExpressableJavaTypeDescriptor(); } + @Override + public Class getBindableJavaType() { + return getJavaTypeDescriptor().getJavaTypeClass(); + } + @Override public X accept(SemanticQueryWalker walker) { return walker.visitFieldLiteral( this ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJpaCriteriaParameterWrapper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJpaCriteriaParameterWrapper.java index 4c4b63ebbe..d371351af7 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJpaCriteriaParameterWrapper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmJpaCriteriaParameterWrapper.java @@ -8,13 +8,14 @@ package org.hibernate.query.sqm.tree.expression; import java.util.function.Consumer; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.tree.select.SqmSelectableNode; import org.hibernate.sql.ast.tree.expression.JdbcParameter; +import static org.hibernate.query.sqm.tree.expression.SqmExpressionHelper.toSqmType; + /** * Acts as the per-use wrapper for a JpaCriteriaParameter ({@link jakarta.persistence.criteria.CriteriaBuilder#parameter}). * @@ -30,7 +31,7 @@ public class SqmJpaCriteriaParameterWrapper AllowableParameterType type, JpaCriteriaParameter jpaCriteriaParameter, NodeBuilder criteriaBuilder) { - super( type, criteriaBuilder ); + super( toSqmType( type, criteriaBuilder ), criteriaBuilder ); this.jpaCriteriaParameter = jpaCriteriaParameter; } @@ -49,16 +50,6 @@ public class SqmJpaCriteriaParameterWrapper return jpaCriteriaParameter; } - @Override - public AllowableParameterType getNodeType() { - SqmExpressable nodeType = super.getNodeType(); - if ( nodeType == null || nodeType instanceof AllowableParameterType ) { - return ( (AllowableParameterType) nodeType ); - } - - throw new IllegalStateException( "Expecting AllowableParameterType as node type" ); - } - @Override public Class getParameterType() { return jpaCriteriaParameter.getParameterType(); @@ -75,7 +66,7 @@ public class SqmJpaCriteriaParameterWrapper } @Override - public SqmParameter copy() { + public SqmParameter copy() { return new SqmJpaCriteriaParameterWrapper<>( getNodeType(), jpaCriteriaParameter, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteralNull.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteralNull.java index 41eff15934..a2eb73aa2e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteralNull.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteralNull.java @@ -15,7 +15,7 @@ import org.hibernate.query.sqm.SemanticQueryWalker; */ public class SqmLiteralNull extends SqmLiteral { - private static final SqmExpressable NULL_TYPE = () -> null; + private static final SqmExpressable NULL_TYPE = NullSqmExpressable.NULL_SQM_EXPRESSABLE; public SqmLiteralNull(NodeBuilder nodeBuilder) { //noinspection unchecked diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmNamedParameter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmNamedParameter.java index cd3f6b87b4..d93367fcce 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmNamedParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmNamedParameter.java @@ -6,9 +6,9 @@ */ package org.hibernate.query.sqm.tree.expression; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmExpressable; /** * Represents a named query parameter in the SQM tree. @@ -25,7 +25,7 @@ public class SqmNamedParameter extends AbstractSqmParameter { public SqmNamedParameter( String name, boolean canBeMultiValued, - AllowableParameterType inherentType, + SqmExpressable inherentType, NodeBuilder nodeBuilder) { super( canBeMultiValued, inherentType, nodeBuilder ); this.name = name; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmParameter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmParameter.java index 3b09505c13..ef9e6822fa 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmParameter.java @@ -6,8 +6,9 @@ */ package org.hibernate.query.sqm.tree.expression; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.criteria.JpaParameterExpression; +import org.hibernate.query.sqm.SqmExpressable; /** * Models a parameter expression declared in the query. @@ -62,7 +63,7 @@ public interface SqmParameter extends SqmExpression, JpaParameterExpressio AllowableParameterType getAnticipatedType(); @Override - AllowableParameterType getNodeType(); + SqmExpressable getNodeType(); /** * Make a copy diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmParameterizedEntityType.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmParameterizedEntityType.java index 2ca4504f63..d7152a7f1f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmParameterizedEntityType.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmParameterizedEntityType.java @@ -24,7 +24,7 @@ public class SqmParameterizedEntityType extends AbstractSqmExpression impl } public SqmParameterizedEntityType(SqmParameter parameterExpression, NodeBuilder nodeBuilder) { - super( parameterExpression.getAnticipatedType(), nodeBuilder ); + super( SqmExpressionHelper.toSqmType( parameterExpression.getAnticipatedType(), nodeBuilder ), nodeBuilder ); this.discriminatorSource = parameterExpression; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmPositionalParameter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmPositionalParameter.java index 29df53e1f8..a84c67040c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmPositionalParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmPositionalParameter.java @@ -6,9 +6,9 @@ */ package org.hibernate.query.sqm.tree.expression; -import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmExpressable; /** * Models a positional parameter expression @@ -28,7 +28,7 @@ public class SqmPositionalParameter extends AbstractSqmParameter { public SqmPositionalParameter( int position, boolean canBeMultiValued, - AllowableParameterType expressableType, + SqmExpressable expressableType, NodeBuilder nodeBuilder) { super( canBeMultiValued, expressableType, nodeBuilder ); this.position = position; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmToDuration.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmToDuration.java index 95d873b89c..d923da6386 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmToDuration.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmToDuration.java @@ -6,7 +6,7 @@ */ package org.hibernate.query.sqm.tree.expression; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/ParameterCollector.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/ParameterCollector.java index 3d70fa2157..9e418e4685 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/ParameterCollector.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/ParameterCollector.java @@ -11,7 +11,7 @@ import java.util.HashSet; import java.util.Set; import java.util.function.Consumer; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.spi.BaseSemanticQueryWalker; import org.hibernate.query.sqm.tree.SqmExpressableAccessor; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiation.java index 8f46984f6f..30ed846a0e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiation.java @@ -66,7 +66,6 @@ public class SqmDynamicInstantiation } public static > SqmDynamicInstantiation forMapInstantiation(NodeBuilder nodeBuilder) { - //noinspection unchecked return forMapInstantiation( nodeBuilder.getTypeConfiguration().getJavaTypeDescriptorRegistry().getDescriptor( Map.class ), nodeBuilder @@ -83,7 +82,6 @@ public class SqmDynamicInstantiation } public static > SqmDynamicInstantiation forListInstantiation(NodeBuilder nodeBuilder) { - //noinspection unchecked return forListInstantiation( nodeBuilder.getTypeConfiguration().getJavaTypeDescriptorRegistry().getDescriptor( List.class ), nodeBuilder @@ -219,6 +217,11 @@ public class SqmDynamicInstantiation public JavaType getExpressableJavaTypeDescriptor() { return getTargetTypeDescriptor(); } + + @Override + public Class getBindableJavaType() { + return getTargetTypeDescriptor().getJavaTypeClass(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmJpaCompoundSelection.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmJpaCompoundSelection.java index 34e7b0d9af..18b18adfd2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmJpaCompoundSelection.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmJpaCompoundSelection.java @@ -84,6 +84,11 @@ public class SqmJpaCompoundSelection return getJavaTypeDescriptor().getJavaTypeClass(); } + @Override + public Class getBindableJavaType() { + return getJavaType(); + } + @Override public List> getSelectionItems() { return selectableNodes; @@ -122,5 +127,4 @@ public class SqmJpaCompoundSelection public void visitSubSelectableNodes(Consumer> jpaSelectionConsumer) { selectableNodes.forEach( jpaSelectionConsumer ); } - } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/AbstractJdbcParameter.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/AbstractJdbcParameter.java index d7b686465d..7f093861e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/AbstractJdbcParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/AbstractJdbcParameter.java @@ -14,7 +14,7 @@ import org.hibernate.mapping.IndexedConsumer; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.metamodel.mapping.SqlExpressable; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.expression.JdbcParameter; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallFunctionReturnImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallFunctionReturnImpl.java index 018718b398..b4e88946e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallFunctionReturnImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallFunctionReturnImpl.java @@ -6,7 +6,7 @@ */ package org.hibernate.sql.exec.internal; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.sql.exec.spi.JdbcCallFunctionReturn; import jakarta.persistence.ParameterMode; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallParameterExtractorImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallParameterExtractorImpl.java index 827d6e3b76..f3114f967e 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallParameterExtractorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallParameterExtractorImpl.java @@ -11,7 +11,7 @@ import java.sql.SQLException; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.sql.exec.spi.JdbcCallParameterExtractor; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallParameterRegistrationImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallParameterRegistrationImpl.java index 13b32b114b..1d9612eeae 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallParameterRegistrationImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/JdbcCallParameterRegistrationImpl.java @@ -11,7 +11,7 @@ import java.sql.SQLException; import org.hibernate.engine.jdbc.cursor.spi.RefCursorSupport; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.sql.exec.spi.JdbcCallParameterExtractor; import org.hibernate.sql.exec.spi.JdbcCallParameterRegistration; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcCallParameterRegistration.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcCallParameterRegistration.java index 0a72f2e184..a804f5c11f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcCallParameterRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcCallParameterRegistration.java @@ -11,7 +11,7 @@ import java.sql.CallableStatement; import jakarta.persistence.ParameterMode; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.sql.exec.internal.JdbcCallRefCursorExtractorImpl; /** diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcParameterBindings.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcParameterBindings.java index ff0fec6aa1..d72b7ab617 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcParameterBindings.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcParameterBindings.java @@ -10,7 +10,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; -import java.util.stream.Stream; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.spi.JdbcServices; @@ -19,17 +18,19 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.metamodel.mapping.BasicValuedMapping; import org.hibernate.metamodel.mapping.Bindable; import org.hibernate.metamodel.mapping.JdbcMapping; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.query.internal.BindingTypeHelper; import org.hibernate.query.spi.QueryParameterBinding; import org.hibernate.query.spi.QueryParameterBindings; import org.hibernate.query.spi.QueryParameterImplementor; import org.hibernate.query.sql.internal.NativeQueryImpl; import org.hibernate.query.sql.spi.ParameterOccurrence; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.tree.expression.JdbcParameter; import org.hibernate.sql.exec.internal.JdbcParameterBindingImpl; import org.hibernate.sql.exec.internal.JdbcParameterImpl; +import org.hibernate.type.BasicTypeReference; /** * Access to all of the externalized JDBC parameter bindings @@ -100,7 +101,7 @@ public interface JdbcParameterBindings { BindingTypeHelper.INSTANCE.resolveBindType( jdbcValue, type, - session.getTypeConfiguration() + session.getFactory().getTypeConfiguration() ), jdbcValue ) @@ -113,24 +114,34 @@ public interface JdbcParameterBindings { default void registerNativeQueryParameters( QueryParameterBindings queryParameterBindings, - List parameterList, + List parameterOccurrences, List jdbcParameterBinders, SessionFactoryImplementor factory) { final Dialect dialect = factory.getServiceRegistry().getService( JdbcServices.class ).getJdbcEnvironment().getDialect(); final boolean paddingEnabled = factory.getSessionFactoryOptions().inClauseParameterPaddingEnabled(); final int inExprLimit = dialect.getInExpressionCountLimit(); - for ( ParameterOccurrence occurrence : parameterList ) { + for ( ParameterOccurrence occurrence : parameterOccurrences ) { final QueryParameterImplementor param = occurrence.getParameter(); final QueryParameterBinding binding = queryParameterBindings.getBinding( param ); - AllowableParameterType type = binding.getBindType(); + + final JdbcMapping jdbcMapping; + + final AllowableParameterType type = determineParamType( param, binding ); if ( type == null ) { - type = param.getHibernateType(); + jdbcMapping = factory.getTypeConfiguration().getBasicTypeForJavaType( Object.class ); } - if ( type == null ) { - type = factory.getTypeConfiguration().getBasicTypeForJavaType( Object.class ); + else if ( type instanceof BasicTypeReference ) { + jdbcMapping = factory.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( ( (BasicTypeReference) type ) ); + } + else if ( type instanceof BasicValuedMapping ) { + jdbcMapping = ( (BasicValuedMapping) type ).getJdbcMapping(); + } + else { + throw new IllegalArgumentException( "Could not resolve NativeQuery parameter type : `" + param + "`"); } - final JdbcMapping jdbcMapping = ( (BasicValuedMapping) type ).getJdbcMapping(); if ( binding.isMultiValued() ) { final Collection bindValues = binding.getBindValues(); @@ -165,4 +176,12 @@ public interface JdbcParameterBindings { } } } + + private AllowableParameterType determineParamType(QueryParameterImplementor param, QueryParameterBinding binding) { + AllowableParameterType type = binding.getBindType(); + if ( type == null ) { + type = param.getHibernateType(); + } + return type; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/BasicTypeReference.java b/hibernate-core/src/main/java/org/hibernate/type/BasicTypeReference.java index 06b1b56e47..5118123562 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/BasicTypeReference.java +++ b/hibernate-core/src/main/java/org/hibernate/type/BasicTypeReference.java @@ -8,16 +8,19 @@ package org.hibernate.type; import java.io.Serializable; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.model.convert.spi.BasicValueConverter; +import org.hibernate.query.AllowableParameterType; +import org.hibernate.query.sqm.SqmExpressable; /** * A basic type reference. * * @author Christian Beikov */ -public final class BasicTypeReference implements Serializable { +public final class BasicTypeReference implements AllowableParameterType, Serializable { private final String name; - private final Class javaType; + private final Class javaType; private final int sqlTypeCode; private final BasicValueConverter converter; private final boolean forceImmutable; @@ -41,7 +44,8 @@ public final class BasicTypeReference implements Serializable { BasicValueConverter converter, boolean forceImmutable) { this.name = name; - this.javaType = javaType; + //noinspection unchecked + this.javaType = (Class) javaType; this.sqlTypeCode = sqlTypeCode; this.converter = converter; this.forceImmutable = forceImmutable; @@ -51,7 +55,8 @@ public final class BasicTypeReference implements Serializable { return name; } - public Class getJavaType() { + @Override + public Class getBindableJavaType() { return javaType; } @@ -76,4 +81,9 @@ public final class BasicTypeReference implements Serializable { true ); } + + @Override + public SqmExpressable resolveExpressable(SessionFactoryImplementor sessionFactory) { + return sessionFactory.getTypeConfiguration().getBasicTypeRegistry().resolve( this ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java b/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java index 4d4b749615..77ae46f3c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java +++ b/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java @@ -71,7 +71,7 @@ public class BasicTypeRegistry implements Serializable { } } final JavaType javaTypeDescriptor = typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( - typeReference.getJavaType() + typeReference.getBindableJavaType() ); final JdbcType jdbcType = typeConfiguration.getJdbcTypeDescriptorRegistry().getDescriptor( typeReference.getSqlTypeCode() 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 f80e5fc5fd..081720ef96 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java @@ -38,10 +38,10 @@ import org.hibernate.metamodel.EmbeddableInstantiator; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess; import org.hibernate.property.access.spi.PropertyAccess; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.tuple.PropertyFactory; import org.hibernate.tuple.StandardProperty; import org.hibernate.tuple.ValueGeneration; -import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.spi.CompositeTypeImplementor; @@ -818,20 +818,15 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen } @Override - public JavaType getExpressableJavaTypeDescriptor() { - throw new NotYetImplementedFor6Exception( getClass() ); - } - - @Override - public PersistenceType getPersistenceType() { - return PersistenceType.EMBEDDABLE; - } - - @Override - public Class getJavaType() { + public Class getBindableJavaType() { return getReturnedClass(); } + @Override + public SqmExpressable resolveExpressable(SessionFactoryImplementor sessionFactory) { + return sessionFactory.getRuntimeMetamodels().getJpaMetamodel().embeddable( getReturnedClass() ); + } + @Override public void injectMappingModelPart(EmbeddableValuedModelPart part, MappingModelCreationProcess process) { this.mappingModelPart = part; diff --git a/hibernate-core/src/main/java/org/hibernate/type/ProcedureParameterExtractionAware.java b/hibernate-core/src/main/java/org/hibernate/type/ProcedureParameterExtractionAware.java index d44295a6bd..4e0152816e 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ProcedureParameterExtractionAware.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ProcedureParameterExtractionAware.java @@ -6,7 +6,7 @@ */ package org.hibernate.type; -import org.hibernate.metamodel.model.domain.AllowableOutputParameterType; +import org.hibernate.query.AllowableOutputParameterType; /** * Optional {@link Type} contract for implementations that are aware of how to extract values from diff --git a/hibernate-core/src/main/java/org/hibernate/type/SerializableToBlobType.java b/hibernate-core/src/main/java/org/hibernate/type/SerializableToBlobType.java index 9d067e6f50..695e1d1e84 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/SerializableToBlobType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/SerializableToBlobType.java @@ -24,6 +24,7 @@ public class SerializableToBlobType extends AbstractSing private static final long serialVersionUID = 1L; + @SuppressWarnings({ "unchecked", "rawtypes" }) public SerializableToBlobType() { super( BlobJdbcType.DEFAULT, new SerializableJavaTypeDescriptor( Serializable.class ) ); } @@ -34,11 +35,11 @@ public class SerializableToBlobType extends AbstractSing } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) public void setParameterValues(Properties parameters) { ParameterType reader = (ParameterType) parameters.get( PARAMETER_TYPE ); if ( reader != null ) { - setJavaTypeDescriptor( new SerializableJavaTypeDescriptor<>( reader.getReturnedClass() ) ); + setJavaTypeDescriptor( new SerializableJavaTypeDescriptor( reader.getReturnedClass() ) ); } else { String className = parameters.getProperty( CLASS_NAME ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/StandardBasicTypes.java b/hibernate-core/src/main/java/org/hibernate/type/StandardBasicTypes.java index 0625a64608..9886c18b31 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/StandardBasicTypes.java +++ b/hibernate-core/src/main/java/org/hibernate/type/StandardBasicTypes.java @@ -35,11 +35,7 @@ import java.util.UUID; import org.hibernate.type.spi.TypeConfiguration; /** - * Centralizes access to the standard set of basic {@link Type types}. - *

- * Type mappings can be adjusted per {@link org.hibernate.SessionFactory}. - * - * @see BasicTypeRegistry + * References to common {@link BasicTypeReference} instances * * @author Gavin King * @author Steve Ebersole 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 0ab23feeb7..3549742662 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 @@ -10,6 +10,8 @@ import java.io.InvalidObjectException; import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; +import java.sql.Time; +import java.sql.Timestamp; import java.sql.Types; import java.time.Duration; import java.time.LocalDate; @@ -63,9 +65,6 @@ import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptorIndicators; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; import org.hibernate.type.internal.BasicTypeImpl; -import java.sql.Time; -import java.sql.Timestamp; - import jakarta.persistence.TemporalType; import static org.hibernate.internal.CoreLogging.messageLogger; @@ -321,27 +320,30 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable { } /** - * Encapsulation of lifecycle concerns for a TypeConfiguration, mainly in - * regards to eventually being associated with a SessionFactory. Goes - * 3 "lifecycle" stages, pertaining to {@link #getMetadataBuildingContext()} - * and {@link #getSessionFactory()}: + * Encapsulation of lifecycle concerns for a TypeConfiguration:

    + *
  1. + * "Boot" is where the {@link TypeConfiguration} is first + * built as the boot-model ({@link org.hibernate.boot.model}) of + * the user's domain model is converted into the runtime-model + * ({@link org.hibernate.metamodel.model}). During this phase, + * {@link #getMetadataBuildingContext()} will be accessible but + * {@link #getSessionFactory} will throw an exception. + *
  2. + *
  3. + * "Runtime" is where the runtime-model is accessible. During this + * phase {@link #getSessionFactory()} is accessible while + * {@link #getMetadataBuildingContext()} will now throw an exception + *
  4. + *
  5. + * "Sunset" is after the SessionFactory has been closed. At this point, both + * {@link #getSessionFactory()} and {@link #getMetadataBuildingContext()} + * will now throw an exception + *
  6. + *
+ *

+ * {@link #getServiceRegistry()} is available for both "Boot" and "Runtime". * - * * "Initialization" is where the {@link TypeConfiguration} is first - * built as the "boot model" ({@link org.hibernate.boot.model}) of - * the user's domain model is converted into the "runtime model" - * ({@link org.hibernate.metamodel.model}). During this phase, - * {@link #getMetadataBuildingContext()} will be accessible but - * {@link #getSessionFactory} will throw an exception. - * * "Runtime" is where the "runtime model" is accessible while the - * SessionFactory is still unclosed. During this phase - * {@link #getSessionFactory()} is accessible while - * {@link #getMetadataBuildingContext()} will now throw an - * exception - * * "Sunset" is after the SessionFactory has been closed. During this - * phase both {@link #getSessionFactory()} and - * {@link #getMetadataBuildingContext()} will now throw an exception - * - * Each stage or phase is consider a "scope" for the TypeConfiguration. + * Each stage or phase is consider a scope for the TypeConfiguration. */ private static class Scope implements Serializable { private final TypeConfiguration typeConfiguration; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/CriteriaQueryTypeQueryAdapterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/CriteriaQueryTypeQueryAdapterTest.java index 6c19fe32f1..87be9a3b0f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/CriteriaQueryTypeQueryAdapterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/CriteriaQueryTypeQueryAdapterTest.java @@ -144,7 +144,7 @@ public class CriteriaQueryTypeQueryAdapterTest extends BaseEntityManagerFunction QueryImplementor criteriaQuery = (QueryImplementor) entityManager.createQuery( query ); - criteriaQuery.setParameter( "placedAt", Instant.now(), TemporalType.TIMESTAMP ).list(); + criteriaQuery.setParameter( "placedAt", Instant.now() ).list(); } ); } @@ -162,7 +162,7 @@ public class CriteriaQueryTypeQueryAdapterTest extends BaseEntityManagerFunction QueryImplementor criteriaQuery = (QueryImplementor) entityManager.createQuery( query ); - criteriaQuery.setParameter( "placedAt", Instant.now(), TemporalType.TIMESTAMP ).list(); + criteriaQuery.setParameter( "placedAt", Instant.now() ).list(); } ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ConverterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ConverterTest.java index 813c20ab92..ec3c69f108 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ConverterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ConverterTest.java @@ -13,7 +13,7 @@ import jakarta.persistence.Id; import org.hibernate.SessionFactory; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.query.Query; import org.hibernate.type.Type; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/LongToDateConversionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/LongToDateConversionTest.java index 5e382563c2..a300557e22 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/LongToDateConversionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/LongToDateConversionTest.java @@ -9,14 +9,6 @@ package org.hibernate.orm.test.mapping.converted.converter; import java.io.Serializable; import java.util.Date; import java.util.stream.Stream; -import jakarta.persistence.AttributeConverter; -import jakarta.persistence.Column; -import jakarta.persistence.Convert; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import jakarta.persistence.TemporalType; import org.hibernate.query.Query; @@ -28,6 +20,14 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Column; +import jakarta.persistence.Convert; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -45,7 +45,7 @@ public class LongToDateConversionTest { (session) -> { final String qryStr = "SELECT e FROM TestEntity e WHERE e.date <= :ts"; final Query query = session.createQuery( qryStr, TestEntity.class ); - query.setParameter( "ts", new DateAttribute( System.currentTimeMillis() ), TemporalType.TIMESTAMP ); + query.setParameter( "ts", new DateAttribute( System.currentTimeMillis() ) ); final Stream stream = query.stream(); assertThat( stream.count(), is( 1L ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/SelectClauseTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/SelectClauseTests.java index f9af3a4a2e..d6200f0714 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/SelectClauseTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/SelectClauseTests.java @@ -11,6 +11,7 @@ import java.util.Map; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.CollectionClassification; import org.hibernate.metamodel.model.domain.BasicDomainType; +import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.PluralPersistentAttribute; @@ -167,7 +168,7 @@ public class SelectClauseTests extends BaseSqmUnitTest { private void collectionIndexFunctionAssertions( SqmSelectStatement statement, CollectionClassification expectedCollectionClassification, - Class expectedIndexDomainTypeType, + Class expectedIndexDomainTypeType, String expectedAlias) { assertEquals( 1, statement.getQuerySpec().getSelectClause().getSelections().size() ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sql/NativeQueryParameterTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sql/NativeQueryParameterTests.java index ed43c7197c..0bf19ec297 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sql/NativeQueryParameterTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sql/NativeQueryParameterTests.java @@ -8,19 +8,11 @@ package org.hibernate.orm.test.query.sql; import java.time.Instant; import java.time.temporal.ChronoUnit; -import jakarta.persistence.TemporalType; -import org.hibernate.boot.Metadata; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.event.service.spi.EventListenerRegistry; -import org.hibernate.event.spi.EventType; -import org.hibernate.integrator.spi.Integrator; -import org.hibernate.service.spi.SessionFactoryServiceRegistry; import org.hibernate.type.StandardBasicTypes; import org.hibernate.testing.orm.domain.StandardDomainModel; import org.hibernate.testing.orm.junit.DomainModel; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.junit.jupiter.api.Test; @@ -83,8 +75,8 @@ public class NativeQueryParameterTests { final Instant startPeriod = now.minus( 30, ChronoUnit.DAYS ); session.createNativeQuery( qryString ) - .setParameter( 1, startPeriod, TemporalType.DATE ) - .setParameter( 2, now, TemporalType.DATE ) + .setParameter( 1, startPeriod ) + .setParameter( 2, now ) .list(); } @@ -93,8 +85,8 @@ public class NativeQueryParameterTests { final Instant startPeriod = now.minus( 30, ChronoUnit.DAYS ); session.createNativeQuery( qryString ) - .setParameter( 1, startPeriod, TemporalType.TIMESTAMP ) - .setParameter( 2, now, TemporalType.TIMESTAMP ) + .setParameter( 1, startPeriod ) + .setParameter( 2, now ) .list(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/ArrayType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/ArrayType.java index a808e81cc2..1e09e35a0c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/ArrayType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/contributor/ArrayType.java @@ -6,8 +6,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import org.hibernate.HibernateException; +import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.query.AllowableParameterType; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.type.descriptor.java.BasicJavaType; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; @@ -23,20 +25,17 @@ public class ArrayType implements UserType, AllowableParameterType private final JdbcType jdbcType = VarcharJdbcType.INSTANCE; @Override - public BasicJavaType getExpressableJavaTypeDescriptor() { - return javaType; - } - - @Override - public PersistenceType getPersistenceType() { - return PersistenceType.BASIC; - } - - @Override - public Class getJavaType() { + public Class getBindableJavaType() { + // really a UserType should not implement AllowableParameterType return Array.class; } + @Override + public SqmExpressable resolveExpressable(SessionFactoryImplementor sessionFactory) { + // really a UserType should not implement AllowableParameterType + throw new UnsupportedOperationException(); + } + @Override public int[] sqlTypes() { return new int[] { jdbcType.getJdbcTypeCode() }; diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/function/OrderByFragmentFunction.java b/hibernate-envers/src/main/java/org/hibernate/envers/function/OrderByFragmentFunction.java index c7979537af..30d0f57ef6 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/function/OrderByFragmentFunction.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/function/OrderByFragmentFunction.java @@ -11,7 +11,7 @@ import java.util.List; import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.mapping.ordering.OrderByFragment; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.persister.collection.QueryableCollection; import org.hibernate.persister.entity.Joinable; import org.hibernate.query.NavigablePath; diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialAggregate.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialAggregate.java index f96441ca3e..ee2946ec96 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialAggregate.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialAggregate.java @@ -7,9 +7,7 @@ package org.hibernate.spatial.dialect.hana; import org.hibernate.dialect.function.StandardSQLFunction; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; import org.hibernate.type.BasicTypeReference; -import org.hibernate.type.Type; public class HANASpatialAggregate extends StandardSQLFunction { diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunction.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunction.java index b4700a9ec1..753e4017c0 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunction.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunction.java @@ -11,7 +11,6 @@ import java.util.List; import org.hibernate.dialect.function.StandardSQLFunction; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; import org.hibernate.type.BasicTypeReference; import org.hibernate.type.Type; diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/OracleSpatialFunctions.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/OracleSpatialFunctions.java index 5535718d7d..b647d1bace 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/OracleSpatialFunctions.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/OracleSpatialFunctions.java @@ -11,7 +11,6 @@ import java.util.List; import org.hibernate.QueryException; import org.hibernate.dialect.function.StandardSQLFunction; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; import org.hibernate.spatial.SpatialAnalysis; import org.hibernate.spatial.SpatialFunction; import org.hibernate.spatial.SpatialRelation; diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOObjectProperty.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOObjectProperty.java index 33d7a6a99f..c6e42312ad 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOObjectProperty.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/SDOObjectProperty.java @@ -12,7 +12,7 @@ import org.hibernate.QueryException; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; +import org.hibernate.query.AllowableFunctionReturnType; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; import org.hibernate.query.sqm.function.SqmFunctionDescriptor; diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/WrappedOGCFunction.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/WrappedOGCFunction.java index 1d1089863c..f1f0ac3692 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/WrappedOGCFunction.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/oracle/WrappedOGCFunction.java @@ -11,7 +11,6 @@ import java.util.List; import org.hibernate.dialect.function.StandardSQLFunction; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; import org.hibernate.spatial.Spatial; import org.hibernate.type.BasicTypeReference; import org.hibernate.type.Type;