Jakarta Persistence (JPA) Interface
jakarta.persistence.StoredProcedureQuery
- Super Interfaces:
Query
Interface used to control stored procedure query execution.
Stored procedure query execution may be controlled in accordance with the following:
- The
setParametermethods are used to set the values of all requiredINandINOUTparameters. It is not required to set the values of stored procedure parameters for which default values have been defined by the stored procedure. - When
getResultListandgetSingleResultare called on aStoredProcedureQueryobject, the provider callsexecuteon an unexecuted stored procedure query before processinggetResultListorgetSingleResult. - When
executeUpdateis called on aStoredProcedureQueryobject, the provider will callexecuteon an unexecuted stored procedure query, followed bygetUpdateCount. The results ofexecuteUpdatewill be those ofgetUpdateCount. - The
executemethod supports both the simple case where scalar results are passed back only viaINOUTandOUTparameters as well as the most general case (multiple result sets and/or update counts, possibly also in combination with output parameter values). - The
executemethod returns true if the first result is a result set, and false if it is an update count or there are no results other than throughINOUTandOUTparameters, if any. - If the
executemethod returns true, the pending result set can be obtained by callinggetResultListorgetSingleResult. - The
hasMoreResultsmethod can then be used to test for further results. - If
executeorhasMoreResultsreturns false, thegetUpdateCountmethod can be called to obtain the pending result if it is an update count. ThegetUpdateCountmethod will return either the update count (zero or greater) or -1 if there is no update count (i.e., either the next result is a result set or there is no next update count). - For portability, results that correspond to JDBC result sets and update counts need to be processed before the values of any
INOUTorOUTparameters are extracted. - After results returned through
getResultListandgetUpdateCounthave been exhausted, results returned throughINOUTandOUTparameters can be retrieved. - The
getOutputParameterValuemethods are used to retrieve the values passed back from the procedure throughINOUTandOUTparameters. - When using
REF_CURSORparameters for result sets the update counts should be exhausted before callinggetResultListto retrieve the result set. Alternatively, theREF_CURSORresult set can be retrieved throughgetOutputParameterValue. Result set mappings are applied to results corresponding toREF_CURSORparameters in the order theREF_CURSORparameters were registered with the query. - In the simplest case, where results are returned only via
INOUTandOUTparameters,executecan be followed immediately by calls togetOutputParameterValue.
- See Also:
- Since:
- Jakarta Persistence (JPA) 2.1
Public Instance Methods
boolean execute()- Returns:
- true if first result corresponds to result set.
- Throws:
- if the query execution exceeds the query timeout value set and the transaction is rolled back.PersistenceException- if the query execution exceeds the query timeout value set and only the statement is rolled back.QueryTimeoutException
- Since:
- Jakarta Persistence (JPA) 1.0
int executeUpdate()The provider will call
execute on the query if needed.Overrides
Query.executeUpdate- Returns:
- the update count or -1 if there is no pending result or if the next result is not an update count..
- Throws:
- if the query execution exceeds the query timeout value set and the transaction is rolled back.PersistenceException- if there is no transaction or the persistence context has not been joined to the transaction.TransactionRequiredException- if the statement execution exceeds the query timeout value set and only the statement is rolled back.QueryTimeoutException
- Since:
- Jakarta Persistence (JPA) 1.0
Inherited from
Query- Since:
- Jakarta Persistence (JPA) 3.2
Inherited from
Query- Since:
- Jakarta Persistence (JPA) 3.2
int getFirstResult()Returns
0 if setFirstResult was not applied to the query object.Inherited from
Query- Returns:
- position of the first result.
- Since:
- Jakarta Persistence (JPA) 2.0
The Running JPA Queries article explains how to use
getFirstResult.If a flush mode has not been set for the query object, returns the flush mode in effect for the entity manager.
Inherited from
Query- Returns:
- flush mode.
- Since:
- Jakarta Persistence (JPA) 2.0
Map<String,Object> getHints()Returns null if a lock mode has not been set on the query object.
Inherited from
Query- Returns:
- lock mode.
- Throws:
- if the query is found not to be a Jakarta Persistence query language SELECT query or aIllegalStateExceptionCriteriaQuery<T>query.
- Since:
- Jakarta Persistence (JPA) 2.0
int getMaxResults()Returns
Integer.java.lang.Integer/MAX_VALUE if Query.setMaxResults was not applied to the query object.Inherited from
Query- Returns:
- maximum number of results.
- Since:
- Jakarta Persistence (JPA) 2.0
For portability, all results corresponding to result sets and update counts must be retrieved before the values of output parameters.
- Parameters:
position- parameter position
- Returns:
- the result that is passed back through the parameter.
- Throws:
- if the position does not correspond to a parameter of the query or is not an INOUT or OUT parameter.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 1.0
For portability, all results corresponding to result sets and update counts must be retrieved before the values of output parameters.
- Parameters:
parameterName- name of the parameter as registered or specified in metadata
- Returns:
- the result that is passed back through the parameter.
- Throws:
- if the parameter name does not correspond to a parameter of the query or is not an INOUT or OUT parameter.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 1.0
This method is not required to be supported for native queries.
Inherited from
Query- Parameters:
name- parameter name
- Returns:
- parameter object.
- Throws:
- if invoked on a native query when the implementation does not support this use.IllegalStateException- if the parameter of the specified name does not exist.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 2.0
This method is required to be supported for criteria queries only.
Inherited from
Query- Parameters:
name- parameter nametype- type
- Returns:
- parameter object.
- Throws:
- if invoked on a native query or Jakarta Persistence query language query when the implementation does not support this use.IllegalStateException- if the parameter of the specified name does not exist or is not assignable to the type.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 2.0
This method is not required to be supported for native queries.
Inherited from
Query- Parameters:
position- position
- Returns:
- parameter object.
- Throws:
- if invoked on a native query when the implementation does not support this use.IllegalStateException- if the parameter with the specified position does not exist.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 2.0
This method is not required to be supported by the provider.
Inherited from
Query- Parameters:
position- positiontype- type
- Returns:
- parameter object.
- Throws:
- if invoked on a native query or Jakarta Persistence query language query when the implementation does not support this use.IllegalStateException- if the parameter with the specified position does not exist or is not assignable to the type.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 2.0
(Note that OUT parameters are unbound.)
Inherited from
Query- Parameters:
param- parameter object
- Returns:
- parameter value.
- Throws:
- if the parameter has not been bound.IllegalStateException- if the parameter is not a parameter of the query.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 2.0
(Note that OUT parameters are unbound.)
Inherited from
Query- Parameters:
name- parameter name
- Returns:
- parameter value.
- Throws:
- if the parameter has not been bound.IllegalStateException- if the parameter of the specified name does not exist.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 2.0
(Note that OUT parameters are unbound.)
Inherited from
Query- Parameters:
position- position
- Returns:
- parameter value.
- Throws:
- if the parameter has not been bound.IllegalStateException- if the parameter with the specified position does not exist.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 2.0
Returns empty set if the query has no parameters. This method is not required to be supported for native queries.
Inherited from
Query- Returns:
- set of the parameter objects.
- Throws:
- if invoked on a native query when the implementation does not support this use.IllegalStateException
- Since:
- Jakarta Persistence (JPA) 2.0
List<E> getResultList()The provider will call
execute on the query if needed. A REF_CURSOR result set, if any, is retrieved in the order the REF_CURSOR parameter was registered with the query.Overrides
Query.getResultList- Returns:
- a list of the results or null is the next item is not a result set.
- Throws:
- if the query execution exceeds the query timeout value set and the transaction is rolled back.PersistenceException- if the query execution exceeds the query timeout value set and only the statement is rolled back.QueryTimeoutException
- Since:
- Jakarta Persistence (JPA) 1.0
Stream<T> getResultStream()By default, this method delegates to getResultList().stream(), however persistence provider may choose to override this method to provide additional capabilities.
Inherited from
Query- Returns:
- a stream of the results, or an empty stream if there are no results.
- Throws:
- if called for a Jakarta Persistence query language UPDATE or DELETE statement.IllegalStateException- if pessimistic locking fails and the transaction is rolled back.PessimisticLockException- if pessimistic locking fails and only the statement is rolled back.LockTimeoutException- if the query execution exceeds the query timeout value set and the transaction is rolled back.PersistenceException- if a lock mode other thanTransactionRequiredExceptionNONEhas been set and there is no transaction or the persistence context has not been joined to the transaction.- if the query execution exceeds the query timeout value set and only the statement is rolled back.QueryTimeoutException
- See Also:
- Since:
- Jakarta Persistence (JPA) 2.2
Object getSingleResult()The provider will call
execute on the query if needed. A REF_CURSOR result set, if any, is retrieved in the order the REF_CURSOR parameter was registered with the query.Overrides
Query.getSingleResult- Returns:
- the result or null if the next item is not a result set.
- Throws:
- if there is no result in the next result set.NoResultException- if more than one result.NonUniqueResultException- if the query execution exceeds the query timeout value set and the transaction is rolled back.PersistenceException- if the query execution exceeds the query timeout value set and only the statement is rolled back.QueryTimeoutException
- Since:
- Jakarta Persistence (JPA) 1.0
Object getSingleResultOrNull()The provider will call
execute on the query if needed. A REF_CURSOR result set, if any, is retrieved in the order the REF_CURSOR parameter was registered with the query.Overrides
Query.getSingleResultOrNull- Returns:
- the result or null if the next item is not a result set or if there is no result in the next result set.
- Throws:
- if more than one result.NonUniqueResultException- if the query execution exceeds the query timeout value set and the transaction is rolled back.PersistenceException- if the query execution exceeds the query timeout value set and only the statement is rolled back.QueryTimeoutException
- Since:
- Jakarta Persistence (JPA) 1.0
Integer getTimeout()Inherited from
Query- Since:
- Jakarta Persistence (JPA) 3.2
int getUpdateCount()- Returns:
- update count or -1 if there is no pending result or if the next result is not an update count.
- Throws:
- if the query execution exceeds the query timeout value set and the transaction is rolled back.PersistenceException- if the query execution exceeds the query timeout value set and only the statement is rolled back.QueryTimeoutException
- Since:
- Jakarta Persistence (JPA) 1.0
boolean hasMoreResults()- Returns:
- true if next result corresponds to result set.
- Throws:
- if the query execution exceeds the query timeout value set and the transaction is rolled back.PersistenceException- if the query execution exceeds the query timeout value set and only the statement is rolled back.QueryTimeoutException
- Since:
- Jakarta Persistence (JPA) 1.0
Inherited from
Query- Parameters:
param- parameter object
- Returns:
- boolean indicating whether parameter has been bound.
- Since:
- Jakarta Persistence (JPA) 2.0
StoredProcedureQuery registerStoredProcedureParameter(int position, Class<?> type, ParameterMode mode)All parameters must be registered.
- Parameters:
mode- parameter modeposition- parameter positiontype- type of the parameter
- Returns:
- the same query instance.
- Since:
- Jakarta Persistence (JPA) 1.0
StoredProcedureQuery registerStoredProcedureParameter(String parameterName, Class<?> type, ParameterMode mode)- Parameters:
mode- parameter modeparameterName- name of the parameter as registered or specified in metadatatype- type of the parameter
- Returns:
- the same query instance.
- Since:
- Jakarta Persistence (JPA) 1.0
This cache retrieval mode overrides the cache retrieve mode in use by the entity manager.
Overrides
Query.setCacheRetrieveMode- Parameters:
cacheRetrieveMode- cache retrieval mode
- Returns:
- the same query instance.
- Since:
- Jakarta Persistence (JPA) 3.2
This cache storage mode overrides the cache storage mode in use by the entity manager.
Overrides
Query.setCacheStoreMode- Parameters:
cacheStoreMode- cache storage mode
- Returns:
- the same query instance.
- Since:
- Jakarta Persistence (JPA) 3.2
Inherited from
Query- Parameters:
startPosition- position of the first result, numbered from 0
- Returns:
- the same query instance.
- Throws:
- if the argument is negative.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 1.0
The flush mode type applies to the query regardless of the flush mode type in use for the entity manager.
Overrides
Query.setFlushMode- Parameters:
flushMode- flush mode
- Returns:
- the same query instance.
- Since:
- Jakarta Persistence (JPA) 1.0
The hints elements may be used to specify query properties and hints. Properties defined by this specification must be observed by the provider. Vendor-specific hints that are not recognized by a provider must be silently ignored. Portable applications should not rely on the standard timeout hint. Depending on the database in use, this hint may or may not be observed.
Overrides
Query.setHint- Parameters:
value- value for the property or hinthintName- name of the property or hint
- Returns:
- the same query instance.
- Throws:
- if the second argument is not valid for the implementation.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 1.0
Inherited from
Query- Parameters:
lockMode- lock mode
- Returns:
- the same query instance.
- Throws:
- if the query is found not to be a Jakarta Persistence query language SELECT query or aIllegalStateExceptionCriteriaQuery<T>query.
- Since:
- Jakarta Persistence (JPA) 2.0
Inherited from
Query- Parameters:
maxResult- maximum number of results to retrieve
- Returns:
- the same query instance.
- Throws:
- if the argument is negative.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 1.0
Overrides
Query.setParameter- Parameters:
param- parameter objectvalue- parameter value
- Returns:
- the same query instance.
- Throws:
- if the parameter does not correspond to a parameter of the query.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 1.0
StoredProcedureQuery setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)Overrides
Query.setParameter- Parameters:
temporalType- temporal typeparam- parameter objectvalue- parameter value
- Returns:
- the same query instance.
- Throws:
- if the parameter does not correspond to a parameter of the query.IllegalArgumentException
- Deprecated:
- Newly-written code should use the date/time types defined in
java.time.
- Since:
- Jakarta Persistence (JPA) 1.0
Overrides
Query.setParameter- Parameters:
temporalType- temporal typeparam- parameter objectvalue- parameter value
- Returns:
- the same query instance.
- Throws:
- if the parameter does not correspond to a parameter of the query.IllegalArgumentException
- Deprecated:
- Newly-written code should use the date/time types defined in
java.time.
- Since:
- Jakarta Persistence (JPA) 1.0
Overrides
Query.setParameter- Parameters:
name- parameter namevalue- parameter value
- Returns:
- the same query instance.
- Throws:
- if the parameter name does not correspond to a parameter of the query or if the argument is of incorrect type.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 1.0
Overrides
Query.setParameter- Parameters:
name- parameter nametemporalType- temporal typevalue- parameter value
- Returns:
- the same query instance.
- Throws:
- if the parameter name does not correspond to a parameter of the query or if the value argument is of incorrect type.IllegalArgumentException
- Deprecated:
- Newly-written code should use the date/time types defined in
java.time.
- Since:
- Jakarta Persistence (JPA) 1.0
Overrides
Query.setParameter- Parameters:
name- parameter nametemporalType- temporal typevalue- parameter value
- Returns:
- the same query instance.
- Throws:
- if the parameter name does not correspond to a parameter of the query or if the value argument is of incorrect type.IllegalArgumentException
- Deprecated:
- Newly-written code should use the date/time types defined in
java.time.
- Since:
- Jakarta Persistence (JPA) 1.0
Overrides
Query.setParameter- Parameters:
position- positionvalue- parameter value
- Returns:
- the same query instance.
- Throws:
- if position does not correspond to a positional parameter of the query or if the argument is of incorrect type.IllegalArgumentException
- Since:
- Jakarta Persistence (JPA) 1.0
Overrides
Query.setParameter- Parameters:
position- positiontemporalType- temporal typevalue- parameter value
- Returns:
- the same query instance.
- Throws:
- if position does not correspond to a positional parameter of the query or if the value argument is of incorrect type.IllegalArgumentException
- Deprecated:
- Newly-written code should use the date/time types defined in
java.time.
- Since:
- Jakarta Persistence (JPA) 1.0
Overrides
Query.setParameter- Parameters:
position- positiontemporalType- temporal typevalue- parameter value
- Returns:
- the same query instance.
- Throws:
- if position does not correspond to a positional parameter of the query or if the value argument is of incorrect type.IllegalArgumentException
- Deprecated:
- Newly-written code should use the date/time types defined in
java.time.
- Since:
- Jakarta Persistence (JPA) 1.0
This is a hint, and is an alternative to setting the hint
jakarta.persistence.query.timeout.Overrides
Query.setTimeout- Parameters:
timeout- the timeout, in milliseconds, or null to indicate no timeout
- Returns:
- the same query instance.
- Since:
- Jakarta Persistence (JPA) 3.2
If the provider implementation of
Query does not support the given type, the PersistenceException is thrown.Inherited from
Query- Parameters:
cls- the type of the object to be returned. This is usually either the underlying class implementingQueryor an interface it implements.
- Returns:
- an instance of the specified class.
- Throws:
- if the provider does not support the given type.PersistenceException
- Since:
- Jakarta Persistence (JPA) 2.0