Class ArgumentTypesValidator
java.lang.Object
org.hibernate.query.sqm.produce.function.ArgumentTypesValidator
- All Implemented Interfaces:
ArgumentsValidator
Typechecks the arguments of HQL functions based on the assigned JDBC types.
- API Note:
- Originally, the main purpose for doing this was that we wanted to be able to check named queries at startup or build time, and we wanted to be able to check all queries in the IDE. But since Hibernate 6 it's of more general importance.
- Implementation Note:
- Access to the
MappingMetamodelis very problematic here, since we are sometimes called in a context where we have not built aSessionFactoryImpl, and therefore we have no persisters.
-
Constructor Summary
ConstructorsConstructorDescriptionArgumentTypesValidator(ArgumentsValidator delegate, FunctionParameterType... types) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckArgumentType(int paramNumber, String functionName, FunctionParameterType type, JdbcType jdbcType, Type javaType) Pretty-print the signature of the argument list.static booleanisUnknownExpressionType(JdbcMappingContainer expressionType) We can't validate some expressions involving parameters / unknown functions.voidvalidate(List<? extends SqmTypedNode<?>> arguments, String functionName, BindingContext bindingContext) We do an initial validation phase with just the SQM tree, even though we don't have all typing information available here (in particular, we don't have the final JDBC type codes for things with converters) because this is the phase that is run at startup for named queries, and can be done in an IDE.voidvalidateSqlTypes(List<? extends SqlAstNode> arguments, String functionName) This is the final validation phase with the fully-typed SQL nodes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.hibernate.query.sqm.produce.function.ArgumentsValidator
validate
-
Constructor Details
-
ArgumentTypesValidator
-
-
Method Details
-
validate
public void validate(List<? extends SqmTypedNode<?>> arguments, String functionName, BindingContext bindingContext) We do an initial validation phase with just the SQM tree, even though we don't have all typing information available here (in particular, we don't have the final JDBC type codes for things with converters) because this is the phase that is run at startup for named queries, and can be done in an IDE.- Specified by:
validatein interfaceArgumentsValidator
-
validateSqlTypes
This is the final validation phase with the fully-typed SQL nodes. Note that these checks are much less useful, occurring "too late", right before we execute the query and get an error from the database. However, they help in the sense of (a) resulting in more consistent/understandable error messages, and (b) protecting the user from writing queries that depend on generally-unportable implicit type conversions happening at the database level. (Implicit type conversions between numeric types are portable, and are not prohibited here.)- Specified by:
validateSqlTypesin interfaceArgumentsValidator
-
isUnknownExpressionType
We can't validate some expressions involving parameters / unknown functions. -
checkArgumentType
@Internal public static void checkArgumentType(int paramNumber, String functionName, FunctionParameterType type, JdbcType jdbcType, Type javaType) -
getSignature
Description copied from interface:ArgumentsValidatorPretty-print the signature of the argument list.- Specified by:
getSignaturein interfaceArgumentsValidator
-