Interface TypedQuery<X>
- Type Parameters:
X- query result type
- All Superinterfaces:
Query
SELECT
queries are typed queries, since only a SELECT query
can return a result. A DELETE or UPDATE query
is not a typed query and is always represented by an untyped
instance of Query, usually, by a Statement.
On the other hand, a native SQL query is considered a typed
query if it returns a result set.- Since:
- 2.0
- See Also:
- API note:
- Just like any other data access API, including JDBC itself, native SQL query strings and Jakarta Persistence query language strings executed via this API must never be composed by concatenating user input or other untrusted data. User input should be properly validated and passed as a parameter to a parameterized query string. In particular, native SQL query strings executed via this API are typically executed verbatim with no additional validation or sanitization beyond that performed by the JDBC driver.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAn option influencing execution of a typed query. -
Method Summary
Modifier and TypeMethodDescriptionaddOption(TypedQuery.Option option) Specify an option influencing execution of this typed query, overwriting any existing option of the same type.intDeprecated, for removal: This API element is subject to removal in a future version.The cache retrieval mode in effect during query execution.The cache storage mode in effect during query execution.intThe position of the first result returned to the client, as specified bysetFirstResult(int), or0ifsetFirstResult(int)was not called.The current lock mode for the query ornullif a lock mode has not been set.The current pessimistic lock scope for the query ornullif a scope has not been set.intThe maximum number of results returned to the client, as specified bysetMaxResults(int), or 2147483647 ifsetMaxResults(int)was not called.Get the options influencing execution of this typed query.longExecute the query and return the query results as a typedList<X>.Execute the query and return the query results as a typedStream<X>.Execute the query, returning a single typed result.Execute the query, returning a single typed result, ornullif the query has no results.setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) Set the cache retrieval mode in effect during query execution.setCacheStoreMode(CacheStoreMode cacheStoreMode) Set the cache storage mode in effect during query execution.<P> TypedQuery<X> 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.<P> TypedQuery<X> 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.setFirstResult(int startPosition) Set the position of the first query result returned to the client.setFlushMode(FlushModeType flushMode) Deprecated.Set a query property or hint.setLockMode(LockModeType lockMode) Set the lock mode type to use when the query is executed.setLockScope(PessimisticLockScope lockScope) Set the pessimistic lock scope to use when the query is executed if a pessimistic lock mode is specified viasetLockMode(LockModeType).setMaxResults(int maxResult) Set the maximum number of results returned to the client.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> TypedQuery<X> setParameter(int position, P value, Type<P> type) Bind an argument value to a positional parameter, explicitly specifying the parameter type.<P> TypedQuery<X> setParameter(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> TypedQuery<X> setParameter(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> TypedQuery<X> setParameter(String name, P value, Type<P> type) Bind an argument value to a named parameter, explicitly specifying the parameter type.<P> TypedQuery<X> setParameter(String name, P value, Class<P> type) Bind an argument value to a named parameter, explicitly specifying the parameter type.setQueryFlushMode(QueryFlushMode flushMode) Set the query flush mode to be used when the query is executed.setTimeout(Timeout timeout) Set the query timeout.setTimeout(Integer timeout) Set the query timeout, in milliseconds.Methods inherited from interface Query
getFlushMode, getHints, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, getQueryFlushMode, getTimeout, isBound, unwrap
-
Method Details
-
getResultCount
long getResultCount()Determine the maximum number of results that could in principle be returned by the query if no offset or limit were applied.
The
getResultCountmethod should not cause query results to be fetched from the database.- Returns:
- the maximum number of results that could in principle be returned by the query if no offset or limit were applied
- 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 backPersistenceException- if the query execution exceeds the query timeout value set and the transaction is rolled back- Since:
- 4.0
-
getResultList
Execute the query and return the query results as a typedList<X>. If necessary, first synchronize changes with the database by flushing the persistence context.- Specified by:
getResultListin interfaceQuery- Returns:
- a list of the results, each of type
X, 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
-
getSingleResult
X getSingleResult()Execute the query, returning a single typed result. If necessary, first synchronize changes with the database by flushing the persistence context.- Specified by:
getSingleResultin interfaceQuery- Returns:
- the result, of type
X - 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
-
getResultStream
Execute the query and return the query results as a typedStream<X>. 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.- Specified by:
getResultStreamin interfaceQuery- Returns:
- a stream of the results, each of type
X, 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:
-
getSingleResultOrNull
Execute the query, returning a single typed result, ornullif the query has no results. If necessary, first synchronize changes with the database by flushing the persistence context.- Specified by:
getSingleResultOrNullin interfaceQuery- Returns:
- the result, of type
X, ornullif 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
-
setMaxResults
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.- Specified by:
setMaxResultsin interfaceQuery- Parameters:
maxResult- The maximum number of results- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the argument is negative
-
setFirstResult
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.- Specified by:
setFirstResultin interfaceQuery- Parameters:
startPosition- The position of the first result, numbered from0- Returns:
- the same query instance
- Throws:
IllegalArgumentException- if the argument is negative
-
getMaxResults
int getMaxResults()The maximum number of results returned to the client, as specified bysetMaxResults(int), or 2147483647 ifsetMaxResults(int)was not called.- Specified by:
getMaxResultsin interfaceQuery- Returns:
- the maximum number of results
- Since:
- 2.0
-
getFirstResult
int getFirstResult()The position of the first result returned to the client, as specified bysetFirstResult(int), or0ifsetFirstResult(int)was not called.- Specified by:
getFirstResultin interfaceQuery- Returns:
- the position of the first result
- Since:
- 2.0
-
setHint
Set a query property or hint. Properties defined by this specification must be observed by the persistence 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.- Specified by:
setHintin interfaceQuery- 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 given property or hint name is recognized by the provider, but the second argument is not a legal value for the given property or hint- API note:
- The use of named hints lacks type safety compared to the use of options.
-
setParameter
Bind an argument to a parameter of this query respresented as aParameterobject.- Specified by:
setParameterin interfaceQuery- Type Parameters:
T- the parameter type- 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
-
setParameter
@Deprecated(since="3.2") @Nonnull TypedQuery<X> setParameter(@Nonnull Parameter<Calendar> param, @Nullable Calendar value, @Nonnull TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.- Specified by:
setParameterin interfaceQuery- 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
-
setParameter
@Deprecated(since="3.2") @Nonnull TypedQuery<X> setParameter(@Nonnull Parameter<Date> param, @Nullable Date value, @Nonnull TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.- Specified by:
setParameterin interfaceQuery- 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
-
setParameter
Bind an argument value to a named parameter.- Specified by:
setParameterin interfaceQuery- 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
@Nonnull <P> TypedQuery<X> setParameter(@Nonnull String name, @Nullable P value, @Nonnull Class<P> type) Bind an argument value to a named parameter, explicitly specifying the parameter type. This is most useful when the argument might benull.var books = em.createNativeQuery("select * from books where :limit is null or pub_date > :limit", Book.class) .setParameter("limit", optionalDateLimit, LocalDate.class) .getResultList();- Specified by:
setParameterin interfaceQuery- Type Parameters:
P- the parameter type- 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
@Nonnull <P> TypedQuery<X> setParameter(@Nonnull String name, @Nullable P value, @Nonnull Type<P> type) 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", Book.class) .setParameter("amount", amount, Book_.price.getType()) .getResultList();- Specified by:
setParameterin interfaceQuery- Type Parameters:
P- the parameter type- 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
@Nonnull <P> TypedQuery<X> setConvertedParameter(@Nonnull String name, @Nullable P value, @Nonnull 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", Book.class) .setConvertedParameter("amount", amount, MonetaryAmountConverter.class) .getResultList();- Specified by:
setConvertedParameterin interfaceQuery- Type Parameters:
P- the parameter type- 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(since="3.2") @Nonnull TypedQuery<X> setParameter(@Nonnull String name, @Nullable Calendar value, @Nonnull TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.Bind an instance ofCalendarto a named parameter.- Specified by:
setParameterin interfaceQuery- 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(since="3.2") @Nonnull TypedQuery<X> setParameter(@Nonnull String name, @Nullable Date value, @Nonnull TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.Bind an instance ofDateto a named parameter.- Specified by:
setParameterin interfaceQuery- 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.- Specified by:
setParameterin interfaceQuery- 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 positional 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.var books = em.createNativeQuery("select * from books where ?1 is null or pub_date > ?1", Book.class) .setParameter(1, optionalDateLimit, LocalDate.class) .getResultList();- Specified by:
setParameterin interfaceQuery- Type Parameters:
P- the parameter type- 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 positional 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", Book.class) .setParameter(1, amount, Book_.price.getType()) .getResultList();- Specified by:
setParameterin interfaceQuery- Type Parameters:
P- the parameter type- 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
@Nonnull <P> TypedQuery<X> setConvertedParameter(int position, @Nullable P value, @Nonnull 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", Book.class) .setConvertedParameter(1, amount, MonetaryAmountConverter.class) .getResultList();- Specified by:
setConvertedParameterin interfaceQuery- Type Parameters:
P- the parameter type- 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") @Nonnull TypedQuery<X> setParameter(int position, @Nullable Calendar value, @Nonnull TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.Bind an instance ofCalendarto a positional parameter.- Specified by:
setParameterin interfaceQuery- 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(since="3.2") @Nonnull TypedQuery<X> setParameter(int position, @Nullable Date value, @Nonnull TemporalType temporalType) Deprecated.Newly written code should use the date/time types defined injava.time.Bind an instance ofDateto a positional parameter.- Specified by:
setParameterin interfaceQuery- 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
-
setQueryFlushMode
Set the query flush mode to be used when the query is executed. This flush mode overrides the flush mode type of the entity manager.- Specified by:
setQueryFlushModein interfaceQuery- Parameters:
flushMode- The new flush mode- Returns:
- the same query instance
- Since:
- 4.0
-
setFlushMode
Deprecated.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.- Specified by:
setFlushModein interfaceQuery- Parameters:
flushMode- The new flush mode- Returns:
- the same query instance
-
setLockMode
Set the lock mode type to use when the query is executed.- Specified by:
setLockModein interfaceQuery- 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:
-
setLockScope
Set the pessimistic lock scope to use when the query is executed if a pessimistic lock mode is specified viasetLockMode(LockModeType). If the query is executed without a pessimistic lock mode, the pessimistic lock scope has no effect.- Parameters:
lockScope- The scope of the pessimistic lock- Returns:
- the same query instance
- Throws:
IllegalStateException- if the query is not a Jakarta Persistence query languageSELECTquery or aCriteriaQuery- Since:
- 4.0
-
getLockMode
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 specified lock scope. 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.- Specified by:
getLockModein interfaceQuery- Returns:
- the current lock mode
- Throws:
IllegalStateException- if the query is not a Jakarta Persistence query languageSELECTquery or aCriteriaQuery- Since:
- 2.0
- See Also:
-
getLockScope
The current pessimistic lock scope for the query ornullif a scope has not been set.The lock scope determines the effect of locking on association join tables, collection tables, and primary and secondary tables of join fetched entities. If no lock scope was explicitly specified, locking behaves as if the lock scope were set to
NORMAL.The pessimistic lock scope has no effect if the lock mode is
nullorNONE.- Returns:
- the current pessimistic lock scope
- Throws:
IllegalStateException- if the query is not a Jakarta Persistence query languageSELECTquery or aCriteriaQuery- Since:
- 4.0
-
setCacheRetrieveMode
Set the cache retrieval mode in effect during query execution. This cache retrieval mode overrides the cache retrieve mode of the entity manager.- Specified by:
setCacheRetrieveModein interfaceQuery- Parameters:
cacheRetrieveMode- The new cache retrieval mode- Returns:
- the same query instance
- Since:
- 3.2
-
setCacheStoreMode
Set the cache storage mode in effect during query execution. This cache storage mode overrides the cache storage mode of the entity manager.- Specified by:
setCacheStoreModein interfaceQuery- Parameters:
cacheStoreMode- The new cache storage mode- Returns:
- the same query instance
- Since:
- 3.2
-
getCacheRetrieveMode
The cache retrieval mode in effect during query execution.- Specified by:
getCacheRetrieveModein interfaceQuery- 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
The cache storage mode in effect during query execution.- Specified by:
getCacheStoreModein interfaceQuery- 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.- Specified by:
setTimeoutin interfaceQuery- Parameters:
timeout- the timeout, in milliseconds, or null to indicate no timeout- Returns:
- the same query instance
- Since:
- 3.2
-
setTimeout
Set the query timeout. This is a hint.- Specified by:
setTimeoutin interfaceQuery- Parameters:
timeout- the timeout, or null to indicate no timeout- Returns:
- the same query instance
- Since:
- 4.0
-
executeUpdate
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:QueryExecute 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.- Specified by:
executeUpdatein interfaceQuery- Returns:
- the number of entities updated or deleted, or the row count of the native SQL statement
-
addOption
Specify an option influencing execution of this typed query, overwriting any existing option of the same type.- Parameters:
option- the option- Returns:
- the same query instance
- Since:
- 4.0
-
getOptions
Get the options influencing execution of this typed query. The returned set includes options set viaaddOption(TypedQuery.Option)along with options specified viasetTimeout(Integer),setQueryFlushMode(QueryFlushMode),setCacheRetrieveMode(CacheRetrieveMode),setCacheStoreMode(CacheStoreMode),setLockMode(LockModeType), andsetLockScope(PessimisticLockScope). Mutation of the returned set does not affect the options of the query.- Returns:
- the options for this query
- Since:
- 4.0
-
TypedQuery.