Interface ProcedureCall
- All Superinterfaces:
AutoCloseable, CommonQueryContract, Query, StoredProcedureQuery, SynchronizeableQuery
- All Known Subinterfaces:
ProcedureCallImplementor<R>
Here we use the terms "procedure" and "function" as follows:
- A procedure is a named database executable called via:
{call procedureName(...)} - A function is a named database executable called via:
{? = call functionName(...)}
Unless explicitly specified, the ProcedureCall is executed using the
procedure call syntax. To explicitly specify that the function call syntax
should be used, call markAsFunctionCall(int). Clients of the JPA-standard
StoredProcedureQuery interface may choose between:
- using
storedProcedureQuery.unwrap(ProcedureCall.class).markAsFunctionCall(returnType), or - setting the "org.hibernate.callableFunction" or "hibernate.procedure.function_return_jdbc_type_code" hint to avoid the cast to a Hibernate-specific class.
When the function call syntax is used:
- parameters must be registered by position (not name),
- the first parameter is considered to represent the function return value
(corresponding to the
?which occurs before the=), and - the first parameter must have mode OUT, INOUT, or REF_CURSOR; IN is illegal.
Depending on the SQL dialect, further constraints are enforced or inferred. For example, on PostgreSQL:
- If a parameter has mode REF_CURSOR,
it's automatically inferred that the call is a function call because this
is the only context in which PostgreSQL returns REF_CURSOR results.
So it's not necessary to call
markAsFunctionCall(int)explicitly. - The restriction that there may be at most one REF_CURSOR mode parameter is enforced.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionaddQueryHint(String hint) Add a database query hint to the SQL query.addSynchronizedEntityClass(Class entityClass) Add all query spaces associated with the entity with the given type.addSynchronizedEntityName(String entityName) Add all query spaces associated with the entity with the given names.addSynchronizedQuerySpace(String querySpace) Add a query space.default voidclose()Release the underlying JDBCCallableStatementTheFunctionReturndescribing the return value of the function, ornullif thisProcedureCallis not a function call.Retrieves access to outputs of this procedure call.getParameterRegistration(int position) Retrieve a previously registered parameter memento by the position under which it was registered.Retrieve a previously registered parameter memento by the name under which it was registered.Get the name of the stored procedure (or function) to be called.Retrieve all registered parameters.booleanDoes thisProcedureCallrepresent a call to a databaseFUNCTION, as opposed to aPROCEDURE?markAsFunctionCall(int sqlType) Mark thisProcedureCallas representing a call to a database function, rather than a database procedure.markAsFunctionCall(Type<?> typeReference) Mark thisProcedureCallas representing a call to a database function, rather than a database procedure.markAsFunctionCall(Class<?> resultType) Mark thisProcedureCallas representing a call to a database function, rather than a database procedure.<T> ProcedureParameter<T> registerParameter(int position, Type<T> type, ParameterMode mode) Basic form for registering a positional parameter.<T> ProcedureParameter<T> registerParameter(int position, Class<T> type, ParameterMode mode) Basic form for registering a positional parameter.<T> ProcedureParameter<T> registerParameter(String parameterName, Type<T> type, ParameterMode mode) Basic form for registering a named parameter.<T> ProcedureParameter<T> registerParameter(String parameterName, Class<T> type, ParameterMode mode) Basic form for registering a named parameter.registerStoredProcedureParameter(int position, Type<?> type, ParameterMode mode) LikeregisterStoredProcedureParameter(int, Class, ParameterMode)but a type reference is given instead of a class for the parameter type.registerStoredProcedureParameter(int position, Class<?> type, ParameterMode mode) registerStoredProcedureParameter(String parameterName, Type<?> type, ParameterMode mode) LikeregisterStoredProcedureParameter(String, Class, ParameterMode)but a type reference is given instead of a class for the parameter type.registerStoredProcedureParameter(String parameterName, Class<?> type, ParameterMode mode) setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) setCacheStoreMode(CacheStoreMode cacheStoreMode) setComment(String comment) Set the comment for this query.<P> ProcedureCallsetConvertedParameter(int position, P value, Class<? extends AttributeConverter<P, ?>> converter) <P> ProcedureCallsetConvertedParameter(String name, P value, Class<? extends AttributeConverter<P, ?>> converter) setFirstResult(int startPosition) setFlushMode(FlushModeType flushMode) Deprecated.Set a hint.setLockMode(LockModeType lockMode) setMaxResults(int maxResults) setParameter(int position, Object value) Bind the given argument to an ordinal query parameter.setParameter(int position, Calendar value, TemporalType temporalType) Deprecated.setParameter(int position, Date value, TemporalType temporalType) Deprecated.<P> ProcedureCallsetParameter(int position, P value, Type<P> type) Bind the given argument to an ordinal query parameter using the givenType.<P> ProcedureCallsetParameter(int position, P value, Class<P> type) setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) Deprecated.setParameter(Parameter<Date> param, Date value, TemporalType temporalType) Deprecated.<T> ProcedureCallsetParameter(Parameter<T> param, T value) setParameter(String name, Object value) Bind the given argument to a named query parameter.setParameter(String name, Calendar value, TemporalType temporalType) Deprecated.setParameter(String name, Date value, TemporalType temporalType) Deprecated.<P> ProcedureCallsetParameter(String name, P value, Type<P> type) Bind the given argument to a named query parameter using the givenType.<P> ProcedureCallsetParameter(String name, P value, Class<P> type) setQueryFlushMode(QueryFlushMode queryFlushMode) Set theQueryFlushModeto use for this query.setTimeout(int timeout) Apply a timeout to the corresponding database query.setTimeout(Timeout timeout) Apply a timeout to the corresponding database query.setTimeout(Integer integer) Apply a timeout to the corresponding database query.Methods inherited from interface CommonQueryContract
asMutationQuery, asSelectionQuery, asSelectionQuery, asSelectionQuery, asSelectionQuery, getComment, getEffectiveFlushMode, getParameterMetadata, getQueryFlushMode, getSession, getTimeout, setParameter, setParameter, setParameter, setParameter, setParameter, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setParameterList, setProperties, setPropertiesMethods inherited from interface Query
asStatement, getCacheRetrieveMode, getCacheStoreMode, getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, getResultStream, isBound, ofType, unwrap, withEntityGraphMethods inherited from interface StoredProcedureQuery
execute, executeUpdate, getOutputParameterValue, getOutputParameterValue, getOutputParameterValue, getResultList, getResultList, getResultList, getSingleResult, getSingleResult, getSingleResult, getSingleResultOrNull, getSingleResultOrNull, getSingleResultOrNull, getUpdateCount, hasMoreResults, registerConvertedParameter, registerConvertedParameter, registerResultParameterMethods inherited from interface SynchronizeableQuery
getSynchronizedQuerySpaces
-
Field Details
-
FUNCTION_RETURN_TYPE_HINT
Deprecated, for removal: This API element is subject to removal in a future version.The hint key indicating the return JDBC type code of a function.- See Also:
-
-
Method Details
-
getProcedureName
String getProcedureName()Get the name of the stored procedure (or function) to be called.- Returns:
- The procedure name.
-
setComment
Description copied from interface:CommonQueryContractSet the comment for this query.If SQL commenting is enabled, the comment will be added to the SQL query sent to the database, which may be useful for identifying the source of troublesome queries.
SQL commenting may be enabled using the configuration property "hibernate.use_sql_comments".
- Specified by:
setCommentin interfaceCommonQueryContract- See Also:
-
addQueryHint
Description copied from interface:CommonQueryContractAdd a database query hint to the SQL query.Multiple query hints may be specified. The operation
Dialect.getQueryHintString(String, List)determines how the hint is actually added to the SQL query.- Specified by:
addQueryHintin interfaceCommonQueryContract
-
setMaxResults
- Specified by:
setMaxResultsin interfaceQuery
-
setFirstResult
- Specified by:
setFirstResultin interfaceQuery
-
setLockMode
- Specified by:
setLockModein interfaceQuery
-
setQueryFlushMode
Description copied from interface:CommonQueryContractSet theQueryFlushModeto use for this query.- Specified by:
setQueryFlushModein interfaceCommonQueryContract- See Also:
-
isFunctionCall
boolean isFunctionCall()Does thisProcedureCallrepresent a call to a databaseFUNCTION, as opposed to aPROCEDURE?- Returns:
trueindicates that this ProcedureCall represents a function call;falseindicates a procedure call.- API Note:
- this will only report whether this
ProcedureCallwas marked as a function via call tomarkAsFunctionCall(int). In particular, it will not returntruewhen using JPA query hint.
-
markAsFunctionCall
Mark thisProcedureCallas representing a call to a database function, rather than a database procedure.- Parameters:
sqlType- TheTypescode for the function return- Returns:
this, for method chaining
-
markAsFunctionCall
Mark thisProcedureCallas representing a call to a database function, rather than a database procedure.- Parameters:
resultType- The result type for the function return- Returns:
this, for method chaining- Since:
- 6.2
-
markAsFunctionCall
Mark thisProcedureCallas representing a call to a database function, rather than a database procedure.- Parameters:
typeReference- The result type for the function return- Returns:
this, for method chaining- Since:
- 6.2
-
registerParameter
Basic form for registering a positional parameter.- Specified by:
registerParameterin interfaceStoredProcedureQuery- Type Parameters:
T- The parameterized Java type of the parameter.- Parameters:
position- The positiontype- The Java type of the parametermode- The parameter mode (in, out, inout)- Returns:
- The parameter registration memento
-
registerParameter
Basic form for registering a positional parameter.- Type Parameters:
T- The parameterized Java type of the parameter.- Parameters:
position- The positiontype- The type reference of the parameter typemode- The parameter mode (in, out, inout)- Returns:
- The parameter registration memento
-
registerStoredProcedureParameter
LikeregisterStoredProcedureParameter(int, Class, ParameterMode)but a type reference is given instead of a class for the parameter type. -
getParameterRegistration
Retrieve a previously registered parameter memento by the position under which it was registered.- Parameters:
position- The parameter position- Returns:
- The parameter registration memento
- Throws:
ParameterStrategyException- If the ProcedureCall is defined using named parametersNoSuchParameterException- If no parameter with that position exists
-
registerParameter
<T> ProcedureParameter<T> registerParameter(String parameterName, Class<T> type, ParameterMode mode) throws NamedParametersNotSupportedException Basic form for registering a named parameter.- Specified by:
registerParameterin interfaceStoredProcedureQuery- Type Parameters:
T- The parameterized Java type of the parameter.- Parameters:
parameterName- The parameter nametype- The Java type of the parametermode- The parameter mode (in, out, inout)- Returns:
- The parameter registration memento
- Throws:
NamedParametersNotSupportedException- When the underlying database is known to not support named procedure parameters.
-
registerParameter
<T> ProcedureParameter<T> registerParameter(String parameterName, Type<T> type, ParameterMode mode) throws NamedParametersNotSupportedException Basic form for registering a named parameter.- Type Parameters:
T- The parameterized Java type of the parameter.- Parameters:
parameterName- The parameter nametype- The type reference of the parameter typemode- The parameter mode (in, out, inout)- Returns:
- The parameter registration memento
- Throws:
NamedParametersNotSupportedException- When the underlying database is known to not support named procedure parameters.
-
registerStoredProcedureParameter
ProcedureCall registerStoredProcedureParameter(String parameterName, Type<?> type, ParameterMode mode) LikeregisterStoredProcedureParameter(String, Class, ParameterMode)but a type reference is given instead of a class for the parameter type. -
getParameterRegistration
Retrieve a previously registered parameter memento by the name under which it was registered.- Parameters:
name- The parameter name- Returns:
- The parameter registration memento
- Throws:
ParameterStrategyException- If the ProcedureCall is defined using positional parametersNoSuchParameterException- If no parameter with that name exists
-
getRegisteredParameters
List<ProcedureParameter<?>> getRegisteredParameters()Retrieve all registered parameters.- Returns:
- The (immutable) list of all registered parameters.
-
getOutputs
ProcedureOutputs getOutputs()Retrieves access to outputs of this procedure call. Can be called multiple times, returning the same ProcedureOutputs instance each time.If the procedure call has not actually be executed yet, it will be executed and then the ProcedureOutputs will be returned.
- Returns:
- The ProcedureOutputs representation
-
getFunctionReturn
TheFunctionReturndescribing the return value of the function, ornullif thisProcedureCallis not a function call.- Since:
- 7.0
-
close
default void close()Release the underlying JDBCCallableStatement- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStoredProcedureQuery
-
setTimeout
Description copied from interface:CommonQueryContractApply a timeout to the corresponding database query.- Specified by:
setTimeoutin interfaceCommonQueryContract- Specified by:
setTimeoutin interfaceQuery- Specified by:
setTimeoutin interfaceStoredProcedureQuery- See Also:
-
setTimeout
Description copied from interface:CommonQueryContractApply a timeout to the corresponding database query.- Specified by:
setTimeoutin interfaceCommonQueryContract- See Also:
-
setTimeout
Description copied from interface:CommonQueryContractApply a timeout to the corresponding database query.- Specified by:
setTimeoutin interfaceCommonQueryContract- Specified by:
setTimeoutin interfaceQuery- Specified by:
setTimeoutin interfaceStoredProcedureQuery
-
addSynchronizedQuerySpace
Description copied from interface:SynchronizeableQueryAdd a query space. The effect of this call is to:- force an auto-flush if any entity associated with the current session and mapped to the given query space has pending changes which have not yet been synchronized with the database, and
- if the result set of this query is cached, mark it for invalidation when any entity mapped to the given query space is synchronized with the database in any session.
- Specified by:
addSynchronizedQuerySpacein interfaceSynchronizeableQuery- Parameters:
querySpace- The name of the query space, usually the name of a database table.- Returns:
this, for method chaining
-
addSynchronizedEntityName
Description copied from interface:SynchronizeableQueryAdd all query spaces associated with the entity with the given names.Same as
SynchronizeableQuery.addSynchronizedQuerySpace(String)for all tables mapped by the given entity.- Specified by:
addSynchronizedEntityNamein interfaceSynchronizeableQuery- Parameters:
entityName- The name of an entity.- Returns:
this, for method chaining- Throws:
MappingException- Indicates the given name could not be resolved as an entity
-
addSynchronizedEntityClass
Description copied from interface:SynchronizeableQueryAdd all query spaces associated with the entity with the given type.Same as
SynchronizeableQuery.addSynchronizedQuerySpace(String)for all tables mapped by the given entity.- Specified by:
addSynchronizedEntityClassin interfaceSynchronizeableQuery- Parameters:
entityClass- The class of the entity.- Returns:
this, for method chaining- Throws:
MappingException- Indicates the given class could not be resolved as an entity
-
setHint
Description copied from interface:CommonQueryContractSet a hint. Hints are a JPA-standard way to control provider-specific behavior affecting execution of the query. Clients of native Hibernate API should make use of type-safe operations of this interface and of its subtypes. For example,SelectionQuery.setCacheRegion(String)is preferred overHibernateHints.HINT_CACHE_REGION.The hints understood by Hibernate are enumerated by
AvailableHints.- Specified by:
setHintin interfaceCommonQueryContract- Specified by:
setHintin interfaceQuery- Specified by:
setHintin interfaceStoredProcedureQuery- See Also:
-
setParameter
- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
@Deprecated ProcedureCall setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) Deprecated.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
@Deprecated ProcedureCall setParameter(Parameter<Date> param, Date value, TemporalType temporalType) Deprecated.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
Description copied from interface:CommonQueryContractBind the given argument to a named query parameter.If the type of the parameter cannot be inferred from the context in which it occurs, use one of the overloads which accepts a "type", or pass a
TypedParameterValue.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
Deprecated.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
Deprecated.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
Description copied from interface:CommonQueryContractBind the given argument to a named query parameter using the givenClassreference to attempt to infer theType. If unable to infer an appropriateType, fall back toCommonQueryContract.setParameter(String, Object).- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
Description copied from interface:CommonQueryContractBind the given argument to a named query parameter using the givenType.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setConvertedParameter
<P> ProcedureCall setConvertedParameter(String name, P value, Class<? extends AttributeConverter<P, ?>> converter) - Specified by:
setConvertedParameterin interfaceCommonQueryContract- Specified by:
setConvertedParameterin interfaceQuery- Specified by:
setConvertedParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
Description copied from interface:CommonQueryContractBind the given argument to an ordinal query parameter.If the type of the parameter cannot be inferred from the context in which it occurs, use one of the overloads which accepts a "type", or pass a
TypedParameterValue.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setConvertedParameter
<P> ProcedureCall setConvertedParameter(int position, P value, Class<? extends AttributeConverter<P, ?>> converter) - Specified by:
setConvertedParameterin interfaceCommonQueryContract- Specified by:
setConvertedParameterin interfaceQuery- Specified by:
setConvertedParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
Description copied from interface:CommonQueryContractBind the given argument to an ordinal query parameter using the givenClassreference to attempt to infer theType. If unable to infer an appropriateType, fall back toCommonQueryContract.setParameter(int, Object).- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
Description copied from interface:CommonQueryContractBind the given argument to an ordinal query parameter using the givenType.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery
-
setParameter
Deprecated.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setParameter
Deprecated.- Specified by:
setParameterin interfaceCommonQueryContract- Specified by:
setParameterin interfaceQuery- Specified by:
setParameterin interfaceStoredProcedureQuery- See Also:
-
setFlushMode
Deprecated.- Specified by:
setFlushModein interfaceQuery- Specified by:
setFlushModein interfaceStoredProcedureQuery
-
registerStoredProcedureParameter
- Specified by:
registerStoredProcedureParameterin interfaceStoredProcedureQuery
-
registerStoredProcedureParameter
ProcedureCall registerStoredProcedureParameter(String parameterName, Class<?> type, ParameterMode mode) - Specified by:
registerStoredProcedureParameterin interfaceStoredProcedureQuery
-
setCacheStoreMode
- Specified by:
setCacheStoreModein interfaceQuery- Specified by:
setCacheStoreModein interfaceStoredProcedureQuery
-
setCacheRetrieveMode
- Specified by:
setCacheRetrieveModein interfaceQuery- Specified by:
setCacheRetrieveModein interfaceStoredProcedureQuery
-
HibernateHints.HINT_CALLABLE_FUNCTION_RETURN_TYPE.