Interface Query
- All Known Subinterfaces:
Statement, StoredProcedureQuery, TypedQuery<X>
- For a Jakarta Persistence
UPDATEorDELETEstatement, or for a native SQL statement that returns a row count, an instanceStatementshould be used to execute the statement. - For a Jakarta Persistence
SELECTquery or for any native SQL query that returns a result set, an instance ofTypedQueryshould be used. - For a stored procedure call, a
StoredProcedureQueryshould be used.
If an instance of this interface represents an UPDATE
or DELETE statement, then a Statement representing
the same statement may be obtained by calling asStatement().
int updated =
em.createQuery("delete from Temporary where timestamp > ?1")
.asStatement()
.setParameter(1, cutoffDateTime)
.execute();
If an instance of this interface represents a SELECT
query, then a TypedQuery representing the same query may
be obtained by calling ofType(Class), passing the result
type of the query.
List<Book> books =
em.createQuery("from Book where extract(year from publicationDate) > :year")
.ofType(Book.class)
.setParameter("year", Year.of(2000))
.setMaxResults(10)
.setCacheRetrieveMode(CacheRetrieveMode.BYPASS)
.getResultList();
These operations may be viewed as a sort of type cast to a given subtype of this interface.
- Since:
- 1.0
- See Also:
- API note:
- Every operation only relevant to
SELECTqueries, for example,getResultList()andsetMaxResults(int), is now declared deprecated by this interface. Such operations should be invoked via theTypedQueryinterface. Similarly, the operationexecuteUpdate(), which was only used to execute statements, is declared as deprecated; the new operationStatement.execute()should be used instead.
-
Method Summary
Modifier and TypeMethodDescriptionObtain aStatementrepresenting this query, which must be some kind of executable statement, that is, a Jakarta PersistenceUPDATEorDELETEstatement, or any native SQL statement that returns a row count.intDeprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.intDeprecated, for removal: This API element is subject to removal in a future version.Get the flush mode which will be in effect when the query is executed.getHints()Get the properties and hints and associated values that are in effect for the query instance.Deprecated, for removal: This API element is subject to removal in a future version.intDeprecated, for removal: This API element is subject to removal in a future version.Parameter<?> getParameter(int position) Get theParameterobject representing the declared positional parameter with the given position.<T> Parameter<T> getParameter(int position, Class<T> type) Get theParameterobject corresponding to the declared positional parameter with the given position and type.Parameter<?> getParameter(String name) Get theParameterobject representing the declared named parameter with the given name.<T> Parameter<T> getParameter(String name, Class<T> type) Get theParameterobject representing the declared named parameter with the given name and type.Get theParameterobjects representing the declared parameters of the query or an empty set if the query has no parameters.getParameterValue(int position) Return the input value bound to the positional parameter.<T> TgetParameterValue(Parameter<T> parameter) Return the input value bound to the parameter.getParameterValue(String name) Return the input value bound to the named parameter.Deprecated, for removal: This API element is subject to removal in a future version.This method returns a raw type.default StreamDeprecated, for removal: This API element is subject to removal in a future version.This method returns a raw type.Deprecated, for removal: This API element is subject to removal in a future version.UseTypedQuery.getSingleResult()to execute queriesDeprecated, for removal: This API element is subject to removal in a future version.UseTypedQuery.getSingleResult()to execute queriesThe query timeout, in milliseconds, or null for no timeout.booleanReturn a boolean value indicating whether an argument has been bound to the parameter represented by the given parameter object.<R> TypedQuery<R> Obtain aTypedQuerywith the given query result type, which must be a supertype of the result type of this query.setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) Deprecated, for removal: This API element is subject to removal in a future version.setCacheStoreMode(CacheStoreMode cacheStoreMode) Deprecated, for removal: This API element is subject to removal in a future version.<P> QuerysetConvertedParameter(int position, P value, Class<? extends AttributeConverter<P, ?>> converter) Bind an argument value to a named parameter, explicitly specifying an attribute converter to use.<P> QuerysetConvertedParameter(String name, P value, Class<? extends AttributeConverter<P, ?>> converter) Bind an argument value to a named parameter, explicitly specifying an attribute converter to use.setFirstResult(int startPosition) Deprecated, for removal: This API element is subject to removal in a future version.setFlushMode(FlushModeType flushMode) Set the flush mode type to be used when the query is executed.Set a query property or hint.setLockMode(LockModeType lockMode) Deprecated, for removal: This API element is subject to removal in a future version.setMaxResults(int maxResult) Deprecated, for removal: This API element is subject to removal in a future version.setParameter(int position, Object value) Bind an argument value to a positional parameter.setParameter(int position, Calendar value, TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.setParameter(int position, Date value, TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.<P> QuerysetParameter(int position, P value, Type<P> type) Bind an argument value to a positional parameter, explicitly specifying the parameter type.<P> QuerysetParameter(int position, P value, Class<P> type) Bind an argument value to a positional parameter, explicitly specifying the parameter type.setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.setParameter(Parameter<Date> param, Date value, TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.<T> QuerysetParameter(Parameter<T> parameter, T value) Bind an argument to a parameter of this query respresented as aParameterobject.setParameter(String name, Object value) Bind an argument value to a named parameter.setParameter(String name, Calendar value, TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.setParameter(String name, Date value, TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.<P> QuerysetParameter(String name, P value, Type<P> type) Bind an argument value to a named parameter, explicitly specifying the parameter type.<P> QuerysetParameter(String name, P value, Class<P> type) Bind an argument value to a named parameter, explicitly specifying the parameter type.setTimeout(Timeout timeout) Set the query timeout.setTimeout(Integer timeout) Set the query timeout, in milliseconds.<T> TReturn an object of the specified type to allow access to a provider-specific API.<R> TypedQuery<R> withEntityGraph(EntityGraph<R> graph) Obtain aTypedQuerywith the given entity graph, which must be rooted at a supertype of the result type of this query.
-
Method Details
-
asStatement
Statement asStatement()Obtain aStatementrepresenting this query, which must be some kind of executable statement, that is, a Jakarta PersistenceUPDATEorDELETEstatement, or any native SQL statement that returns a row count. The executable statement may be executed by callingStatement.execute().- Throws:
IllegalStateException- if this query is a Jakarta PersistenceSELECTquery- Since:
- 4.0
-
ofType
Obtain aTypedQuerywith the given query result type, which must be a supertype of the result type of this query. This query must be a Jakarta PersistenceSELECTquery or a native SQL query which returns a result set.- Type Parameters:
R- The query result type- Parameters:
resultType- The Java class of the query result type- Throws:
IllegalArgumentException- if the given result type is not a supertype of the result type of this queryIllegalStateException- if this query is a Jakarta PersistenceUPDATEorDELETEstatement- Since:
- 4.0
-
withEntityGraph
Obtain aTypedQuerywith the given entity graph, which must be rooted at a supertype of the result type of this query. This query must be a Jakarta PersistenceSELECTquery which returns a single entity type.- Type Parameters:
R- The query result type- Parameters:
graph- The entity graph, interpreted as a load graph- Throws:
IllegalArgumentException- if the given graph type is not rooted at a supertype of the result type of this queryIllegalStateException- if this query is a Jakarta PersistenceUPDATEorDELETEstatement- Since:
- 4.0
-
getResultList
Deprecated, for removal: This API element is subject to removal in a future version.This method returns a raw type. UseTypedQuery.getResultList()to execute queries.Execute aSELECTquery or a native query that returns a result set and return the query results as an untypedList. If necessary, first synchronize changes with the database by flushing the persistence context.- Returns:
- a list of the results, or an empty list if there are no results
- Throws:
IllegalStateException- if called for a Jakarta Persistence query language UPDATE or DELETE statementQueryTimeoutException- if the query execution exceeds the query timeout value set and only the statement is rolled backTransactionRequiredException- if a lock mode other thanNONEhas been set and there is no transaction or the persistence context has not been joined to the transactionPessimisticLockException- if pessimistic locking fails and the transaction is rolled backLockTimeoutException- if pessimistic locking fails and only the statement is rolled backPersistenceException- if the query execution exceeds the query timeout value set and the transaction is rolled backPersistenceException- if the flush failsOptimisticLockException- if an optimistic locking conflict is detected during the flush
-
getResultStream
Deprecated, for removal: This API element is subject to removal in a future version.This method returns a raw type. UseTypedQuery.getResultStream()to execute queriesExecute aSELECTquery or a native query that returns a result set and return the query results as an untypedStream. If necessary, first synchronize changes with the database by flushing the persistence context.By default, this method delegates to
getResultList().stream(), The persistence provider may choose to override this method to provide additional capabilities.- Returns:
- a stream of the results, or an empty stream if there are no results
- Throws:
IllegalStateException- if called for a Jakarta Persistence query language UPDATE or DELETE statementQueryTimeoutException- if the query execution exceeds the query timeout value set and only the statement is rolled backTransactionRequiredException- if a lock mode other thanNONEhas been set and there is no transaction or the persistence context has not been joined to the transactionPessimisticLockException- if pessimistic locking fails and the transaction is rolled backLockTimeoutException- if pessimistic locking fails and only the statement is rolled backPersistenceException- if the query execution exceeds the query timeout value set and the transaction is rolled backPersistenceException- if the flush failsOptimisticLockException- if an optimistic locking conflict is detected during the flush- Since:
- 2.2
- See Also:
-
getSingleResult
Deprecated, for removal: This API element is subject to removal in a future version.UseTypedQuery.getSingleResult()to execute queriesExecute aSELECTquery or a native query that returns a result set, returning a single untyped result. If necessary, first synchronize changes with the database by flushing the persistence context.- Returns:
- the result
- Throws:
NoResultException- if there is no resultNonUniqueResultException- if more than one resultIllegalStateException- if called for a Jakarta Persistence query language UPDATE or DELETE statementQueryTimeoutException- if the query execution exceeds the query timeout value set and only the statement is rolled backTransactionRequiredException- if a lock mode other thanNONEhas been set and there is no transaction or the persistence context has not been joined to the transactionPessimisticLockException- if pessimistic locking fails and the transaction is rolled backLockTimeoutException- if pessimistic locking fails and only the statement is rolled backPersistenceException- if the query execution exceeds the query timeout value set and the transaction is rolled backPersistenceException- if the flush failsOptimisticLockException- if an optimistic locking conflict is detected during the flush
-
getSingleResultOrNull
Deprecated, for removal: This API element is subject to removal in a future version.UseTypedQuery.getSingleResult()to execute queriesExecute aSELECTquery or a native query that returns a result set, returning a single untyped result, ornullif the query has no results. If necessary, first synchronize changes with the database by flushing the persistence context.- Returns:
- the result, or
nullif there is no result - Throws:
NonUniqueResultException- if more than one resultIllegalStateException- if called for a Jakarta Persistence query language UPDATE or DELETE statementQueryTimeoutException- if the query execution exceeds the query timeout value set and only the statement is rolled backTransactionRequiredException- if a lock mode other thanNONEhas been set and there is no transaction or the persistence context has not been joined to the transactionPessimisticLockException- if pessimistic locking fails and the transaction is rolled backLockTimeoutException- if pessimistic locking fails and only the statement is rolled backPersistenceException- if the query execution exceeds the query timeout value set and the transaction is rolled backPersistenceException- if the flush failsOptimisticLockException- if an optimistic locking conflict is detected during the flush- Since:
- 3.2
-
executeUpdate
Deprecated, for removal: This API element is subject to removal in a future version.UseStatement.execute().Execute anUPDATEorDELETEstatement or a native SQL statement that returns a row count.After execution of a bulk update or delete operation, the persistence provider is not required to resynchronize state held in memory with the effects of the operation on data held in the database. However, when this method is called within a transaction, the persistence context is joined to the transaction, and
FlushModeType.AUTOis in effect, the persistence provider must ensure that every modification to the state of every entity associated with the persistence context which could possibly alter the effects of the bulk update or delete operation is visible to the processing of the operation.- Returns:
- the number of entities updated or deleted, or the row count of the native SQL statement
- Throws:
IllegalStateException- if called for a Jakarta Persistence query language SELECT statement or for a criteria queryTransactionRequiredException- if there is no transaction or the persistence context has not been joined to the transactionQueryTimeoutException- if the statement execution exceeds the query timeout value set and only the statement is rolled backPersistenceException- if the query execution exceeds the query timeout value set and the transaction is rolled backPersistenceException- if the flush failsOptimisticLockException- if an optimistic locking conflict is detected during the flush
-
setMaxResults
Deprecated, for removal: This API element is subject to removal in a future version.Set the maximum number of results returned to the client. If the query has more results than the given maximum, results are excluded from the list returned bygetResultList(), so that only the given number of results is returned. If the query returns results with a well-defined order, the excluded results must be those which would otherwise occur later in the list.- Parameters:
maxResult- The maximum number of results- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the argument is negative
-
getMaxResults
Deprecated, for removal: This API element is subject to removal in a future version.The maximum number of results returned to the client, as specified bysetMaxResults(int), or 2147483647 ifsetMaxResults(int)was not called.- Returns:
- the maximum number of results
- Since:
- 2.0
-
setFirstResult
Deprecated, for removal: This API element is subject to removal in a future version.Set the position of the first query result returned to the client. The given number of results is excluded from the list returned bygetResultList(). If the query returns results with a well-defined order, the excluded results must be those which would otherwise occur earlier in the list.- Parameters:
startPosition- The position of the first result, numbered from0- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the argument is negative
-
getFirstResult
Deprecated, for removal: This API element is subject to removal in a future version.The position of the first result returned to the client, as specified bysetFirstResult(int), or0ifsetFirstResult(int)was not called.- Returns:
- the position of the first result
- Since:
- 2.0
-
setHint
Set a query property or hint. 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 and the locking mechanisms used by the provider, this hint may or may not be observed.- Parameters:
hintName- The name of the property or hintvalue- The value for the property or hint- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the second argument is not valid for the implementation
-
getHints
-
setParameter
Bind an argument to a parameter of this query respresented as aParameterobject.- Parameters:
parameter- The parameter objectvalue- The argument to the parameter- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the parameter does not correspond to a parameter of the query- Since:
- 2.0
-
setParameter
@Deprecated(since="3.2") Query setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.- Parameters:
param- The parameter objectvalue- The argument to the parametertemporalType- A temporal type- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the parameter does not correspond to a parameter of the query- Since:
- 2.0
-
setParameter
@Deprecated(since="3.2") Query setParameter(Parameter<Date> param, Date value, TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.- Parameters:
param- The parameter objectvalue- The argument to the parametertemporalType- A temporal type- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the parameter does not correspond to a parameter of the query- Since:
- 2.0
-
setParameter
Bind an argument value to a named parameter.- Parameters:
name- The name of the parametervalue- The argument to the parameter- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the parameter name does not correspond to a parameter of the query, or if the argument is of incompatible type
-
setParameter
Bind an argument value to a named parameter, explicitly specifying the parameter type. This is most useful when the argument might benull, especially in the case of a native query.em.createNativeQuery("update books set pub_date = :date where isbn = :ISBN") .setParameter("date", optionalPublicationDate, LocalDate.class) .setParameter("ISBN", isbn) .executeUpdate();var books = session.createNativeQuery("select * from books where :limit is null or pub_date > :limit", Book.class) .setParameter("limit", optionalDateLimit, LocalDate.class) .getResultList();- Parameters:
name- The name of the parametervalue- The argument to the parametertype- A class object representing the parameter type- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the parameter name does not correspond to a parameter of the query, or if the argument is of incompatible type- Since:
- 4.0
-
setParameter
Bind an argument value to a named parameter, explicitly specifying the parameter type. This is most useful when the binding is affected by an attribute converter.var amount = MonetaryAmount.of(priceLimit, currency); var affordableBooks = em.createQuery("from Book where price < :amount") .setParameter("amount", amount, Book_.price.getType()) .getResultList();- Parameters:
name- The name of the parametervalue- The argument to the parametertype- TheTypeof the parameter- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the parameter name does not correspond to a parameter of the query, or if the argument is of incompatible type- Since:
- 4.0
-
setConvertedParameter
<P> Query setConvertedParameter(String name, P value, Class<? extends AttributeConverter<P, ?>> converter) Bind an argument value to a named parameter, explicitly specifying an attribute converter to use.var amount = MonetaryAmount.of(priceLimit, currency); var affordableBooks = em.createQuery("from Book where price < :amount") .setConvertedParameter("amount", amount, MonetaryAmountConverter.class) .getResultList();- Parameters:
name- The name of the parametervalue- The argument to the parameterconverter- The class of the attribute converter- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the parameter name does not correspond to a parameter of the query, or if the argument is of incompatible type- Since:
- 4.0
-
setParameter
Deprecated.Newly written code should use the date/time types defined injava.time.Bind an instance ofCalendarto a named parameter.- Parameters:
name- The name of the parametervalue- The argument to the parametertemporalType- A temporal type- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the parameter name does not correspond to a parameter of the query, or if the value argument is of incompatible type
-
setParameter
Deprecated.Newly written code should use the date/time types defined injava.time.Bind an instance ofDateto a named parameter.- Parameters:
name- The name of the parametervalue- The argument to the parametertemporalType- A temporal type- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the parameter name does not correspond to a parameter of the query, or if the value argument is of incompatible type
-
setParameter
Bind an argument value to a positional parameter.- Parameters:
position- The parameter positionvalue- The argument to the parameter- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the given position does not correspond to a parameter of the query, or if the argument is of incompatible type
-
setParameter
Bind an argument value to a positional parameter, explicitly specifying the parameter type. This is most useful when the argument might benull, especially in the case of a native SQL query.em.createNativeQuery("update books set pub_date = ?1 where isbn = ?2") .setParameter(1, optionalPublicationDate, LocalDate.class) .setParameter(2, isbn) .executeUpdate();var books = session.createNativeQuery("select * from books where ?1 is null or pub_date > ?1", Book.class) .setParameter(1, optionalDateLimit, LocalDate.class) .getResultList();- Parameters:
position- The parameter positionvalue- The argument to the parametertype- A class object representing the parameter type- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the given position does not correspond to a parameter of the query, or if the argument is of incompatible type- Since:
- 4.0
-
setParameter
Bind an argument value to a positional parameter, explicitly specifying the parameter type. This is most useful when the binding is affected by an attribute converter.var amount = MonetaryAmount.of(priceLimit, currency); var affordableBooks = em.createQuery("from Book where price < ?1") .setParameter(1, amount, Book_.price.getType()) .getResultList();- Parameters:
position- The parameter positionvalue- The argument to the parametertype- TheTypeof the parameter- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the given position does not correspond to a positional parameter of the query, or if the argument is of incompatible type- Since:
- 4.0
-
setConvertedParameter
<P> Query setConvertedParameter(int position, P value, Class<? extends AttributeConverter<P, ?>> converter) Bind an argument value to a named parameter, explicitly specifying an attribute converter to use.var amount = MonetaryAmount.of(priceLimit, currency); var affordableBooks = em.createQuery("from Book where price < ?1") .setConvertedParameter(1, amount, MonetaryAmountConverter.class) .getResultList();- Parameters:
position- The parameter positionvalue- The argument to the parameterconverter- The class of the attribute converter- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the given position does not correspond to a parameter of the query, or if the argument is of incompatible type- Since:
- 4.0
-
setParameter
@Deprecated(since="3.2") Query setParameter(int position, Calendar value, TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.Bind an instance ofCalendarto a positional parameter.- Parameters:
position- The parameter positionvalue- The argument to the parametertemporalType- A temporal type- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the given position does not correspond to a positional parameter of the query, or if the argument is of incompatible type
-
setParameter
Deprecated.Newly written code should use the date/time types defined injava.time.Bind an instance ofDateto a positional parameter.- Parameters:
position- The parameter positionvalue- The argument to the parametertemporalType- A temporal type- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the given position does not correspond to a positional parameter of the query, or if the argument is of incompatible type
-
getParameters
Get theParameterobjects representing the declared parameters of the query or an empty set if the query has no parameters. This method is not required to be supported for native queries.- Returns:
- a set containing the parameter objects
- Throws:
IllegalStateException- if invoked on a native query when the implementation does not support this use- Since:
- 2.0
-
getParameter
Get theParameterobject representing the declared named parameter with the given name. This method is not required to be supported for native queries.- Parameters:
name- The name of the parameter- Returns:
- The parameter object representing the named parameter
- Throws:
IllegalArgumentException- if the parameter of the specified name does not existIllegalStateException- if invoked on a native query when the implementation does not support this use- Since:
- 2.0
-
getParameter
Get theParameterobject representing the declared named parameter with the given name and type. This method is required to be supported for criteria queries only.- Parameters:
name- The name of the parametertype- A class object representing the parameter type- Returns:
- The parameter object representing the named parameter
- Throws:
IllegalArgumentException- if the parameter of the specified name does not exist or is not assignable to the typeIllegalStateException- if invoked on a native query or Jakarta Persistence query language query when the implementation does not support this use- Since:
- 2.0
-
getParameter
Get theParameterobject representing the declared positional parameter with the given position. This method is not required to be supported for native queries.- Parameters:
position- The parameter position- Returns:
- The parameter object representing the positional parameter
- Throws:
IllegalArgumentException- if the parameter with the specified position does not existIllegalStateException- if invoked on a native query when the implementation does not support this use- Since:
- 2.0
-
getParameter
Get theParameterobject corresponding to the declared positional parameter with the given position and type. This method is not required to be supported by the provider.- Parameters:
position- The parameter positiontype- A class object representing the parameter type- Returns:
- The parameter object representing the positional parameter
- Throws:
IllegalArgumentException- if the parameter with the specified position does not exist or is not assignable to the typeIllegalStateException- if invoked on a native query or Jakarta Persistence query language query when the implementation does not support this use- Since:
- 2.0
-
isBound
Return a boolean value indicating whether an argument has been bound to the parameter represented by the given parameter object.- Parameters:
parameter- The parameter object- Returns:
truean argument has been bound, orfalseotherwise- Since:
- 2.0
-
getParameterValue
Return the input value bound to the parameter. (Note that OUT parameters are unbound.)- Parameters:
parameter- The parameter object- Returns:
- parameter value
- Throws:
IllegalArgumentException- if the parameter is not a parameter of the queryIllegalStateException- if the parameter has not been bound- Since:
- 2.0
-
getParameterValue
Return the input value bound to the named parameter. (Note that OUT parameters are unbound.)- Parameters:
name- The name of the parameter- Returns:
- parameter value
- Throws:
IllegalStateException- if the parameter has not been boundIllegalArgumentException- if the parameter of the specified name does not exist- Since:
- 2.0
-
getParameterValue
Return the input value bound to the positional parameter. (Note that OUT parameters are unbound.)- Parameters:
position- The parameter position- Returns:
- parameter value
- Throws:
IllegalStateException- if the parameter has not been boundIllegalArgumentException- if the parameter with the specified position does not exist- Since:
- 2.0
-
setFlushMode
Set the flush mode type to be used when the query is executed. This flush mode overrides the flush mode type of the entity manager.- Parameters:
flushMode- The new flush mode- Returns:
- the same query instance
-
getFlushMode
FlushModeType getFlushMode()Get the flush mode which will be in effect when the query is executed. If a flush mode has not been set for this query object, return the current flush mode type of the entity manager.- Returns:
- flush mode
- Since:
- 2.0
-
setLockMode
Deprecated, for removal: This API element is subject to removal in a future version.Set the lock mode type to use when the query is executed.- Parameters:
lockMode- The new lock mode- Returns:
- the same query instance
- Throws:
IllegalStateException- if the query is not a Jakarta Persistence query languageSELECTquery or aCriteriaQuery- Since:
- 2.0
- See Also:
-
getLockMode
Deprecated, for removal: This API element is subject to removal in a future version.The current lock mode for the query ornullif a lock mode has not been set.The lock mode affects every entity occurring as an item in the SELECT clause, including entities occurring as arguments to constructors. The effect on association join tables, collection tables, and primary and secondary tables of join fetched entities is determined by the lock scope in effect. If no lock scope was explicitly specified, the lock scope defaults to
NORMAL.If the given lock mode is
PESSIMISTIC_READ,PESSIMISTIC_WRITE, orPESSIMISTIC_FORCE_INCREMENT, the lock also affects every entity with an attribute reference occurring in the SELECT clause, except when the attribute reference occurs as an argument to an aggregate function.- Returns:
- the current lock mode
- Throws:
IllegalStateException- if the query is not a Jakarta Persistence query languageSELECTquery or aCriteriaQuery- Since:
- 2.0
-
setCacheRetrieveMode
@Deprecated(since="4.0", forRemoval=true) Query setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) Deprecated, for removal: This API element is subject to removal in a future version.Set the cache retrieval mode in effect during query execution. This cache retrieval mode overrides the cache retrieve mode of the entity manager.- Parameters:
cacheRetrieveMode- The new cache retrieval mode- Returns:
- the same query instance
- Since:
- 3.2
-
setCacheStoreMode
Deprecated, for removal: This API element is subject to removal in a future version.Set the cache storage mode in effect during query execution. This cache storage mode overrides the cache storage mode of the entity manager.- Parameters:
cacheStoreMode- The new cache storage mode- Returns:
- the same query instance
- Since:
- 3.2
-
getCacheRetrieveMode
Deprecated, for removal: This API element is subject to removal in a future version.The cache retrieval mode in effect during query execution.- Returns:
- the current cache retrieval mode set by calling
setCacheRetrieveMode(CacheRetrieveMode)or the cache retrieval mode of the persistence context if no cache retrieval mode has been explicitly specified for this query. - Since:
- 3.2
-
getCacheStoreMode
Deprecated, for removal: This API element is subject to removal in a future version.The cache storage mode in effect during query execution.- Returns:
- the current cache storage mode set by calling
setCacheStoreMode(CacheStoreMode)or the cache storage mode of the persistence context if no cache storage mode has been explicitly specified for this query. - Since:
- 3.2
-
setTimeout
Set the query timeout, in milliseconds. This is a hint, and is an alternative to setting the hintjakarta.persistence.query.timeout.- Parameters:
timeout- the timeout, in milliseconds, or null to indicate no timeout- Returns:
- the same query instance
- Since:
- 3.2
-
setTimeout
-
getTimeout
-
unwrap
Return an object of the specified type to allow access to a provider-specific API. If the provider implementation ofQuerydoes not support the given type, thePersistenceExceptionis thrown.- Parameters:
type- 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:
PersistenceException- if the provider does not support the given type- Since:
- 2.0
-
Statement.execute().