Top Description Methods
jakarta.persistence

public Interface TypedQuery<X>

extends Query
Type Parameters
<X>
query result type
Imports
java.util.List, .Date, .Calendar, java.util.stream.Stream

Interface used to control the execution of typed queries.
Since
2.0
See Also
Query, Parameter

Method Summary

Modifier and TypeMethod and Description
public List<X>

Returns:

a list of the results
getResultList
()

Redeclares jakarta.persistence.Query.getResultList.

Execute a SELECT query and return the query results as a typed List.
public default Stream<X>

Returns:

a stream of the results
getResultStream
()

Overrides default jakarta.persistence.Query.getResultStream.

Execute a SELECT query and return the query results as a typed java.util.stream.Stream.
public X

Returns:

the result
getSingleResult
()

Redeclares jakarta.persistence.Query.getSingleResult.

Execute a SELECT query that returns a single result.
public TypedQuery<X>

Returns:

the same query instance
setFirstResult
(int
position of the first result, numbered from 0
startPosition
)

Redeclares jakarta.persistence.Query.setFirstResult.

Set the position of the first result to retrieve.
public TypedQuery<X>

Returns:

the same query instance
setFlushMode
(FlushModeType
flush mode
flushMode
)

Redeclares jakarta.persistence.Query.setFlushMode.

Set the flush mode type to be used for the query execution.
public TypedQuery<X>

Returns:

the same query instance
setHint
(String
name of property or hint
hintName
,
Object
value for the property or hint
value
)

Redeclares jakarta.persistence.Query.setHint.

Set a query property or hint.
public TypedQuery<X>

Returns:

the same query instance
setLockMode
(LockModeType
lock mode
lockMode
)

Redeclares jakarta.persistence.Query.setLockMode.

Set the lock mode type to be used for the query execution.
public TypedQuery<X>

Returns:

the same query instance
setMaxResults
(int
maximum number of results to retrieve
maxResult
)

Redeclares jakarta.persistence.Query.setMaxResults.

Set the maximum number of results to retrieve.
public <T> TypedQuery<X>

Returns:

the same query instance
setParameter
(Parameter<T>
parameter object
param
,
T
parameter value
value
)

Redeclares jakarta.persistence.Query.setParameter.

Bind the value of a Parameter object.
public TypedQuery<X>

Returns:

the same query instance
setParameter
(Parameter<Calendar>
parameter object
param
,
Calendar
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Calendar to a Parameter object.
public TypedQuery<X>

Returns:

the same query instance
setParameter
(Parameter<Date>
parameter object
param
,
Date
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Date to a Parameter object.
public TypedQuery<X>

Returns:

the same query instance
setParameter
(String
parameter name
name
,
Object
parameter value
value
)

Redeclares jakarta.persistence.Query.setParameter.

Bind an argument value to a named parameter.
public TypedQuery<X>

Returns:

the same query instance
setParameter
(String
parameter name
name
,
Calendar
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Calendar to a named parameter.
public TypedQuery<X>

Returns:

the same query instance
setParameter
(String
parameter name
name
,
Date
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Date to a named parameter.
public TypedQuery<X>

Returns:

the same query instance
setParameter
(int
position
position
,
Object
parameter value
value
)

Redeclares jakarta.persistence.Query.setParameter.

Bind an argument value to a positional parameter.
public TypedQuery<X>

Returns:

the same query instance
setParameter
(int
position
position
,
Calendar
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Calendar to a positional parameter.
public TypedQuery<X>

Returns:

the same query instance
setParameter
(int
position
position
,
Date
parameter value
value
,
TemporalType
temporal type
temporalType
)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Date to a positional parameter.
Inherited from jakarta.persistence.Query:
executeUpdategetFirstResultgetFlushModegetHintsgetLockModegetMaxResultsgetParametergetParametergetParametergetParametergetParametersgetParameterValuegetParameterValuegetParameterValueisBoundunwrap

Method Detail

getResultListback to summary
public List<X> getResultList()

Redeclares jakarta.persistence.Query.getResultList.

Execute a SELECT query and return the query results as a typed List.

Returns:List<X>

a list of the results

Exceptions
IllegalStateException:
if called for a Jakarta Persistence query language UPDATE or DELETE statement
QueryTimeoutException:
if the query execution exceeds the query timeout value set and only the statement is rolled back
TransactionRequiredException:
if a lock mode other than NONE has been set and there is no transaction or the persistence context has not been joined to the transaction
PessimisticLockException:
if pessimistic locking fails and the transaction is rolled back
LockTimeoutException:
if pessimistic locking fails and only the statement is rolled back
PersistenceException:
if the query execution exceeds the query timeout value set and the transaction is rolled back
getResultStreamback to summary
public default Stream<X> getResultStream()

Overrides default jakarta.persistence.Query.getResultStream.

Execute a SELECT query and return the query results as a typed java.util.stream.Stream. By default this method delegates to getResultList().stream(), however persistence provider may choose to override this method to provide additional capabilities.

Returns:Stream<X>

a stream of the results

Exceptions
IllegalStateException:
if called for a Jakarta Persistence query language UPDATE or DELETE statement
QueryTimeoutException:
if the query execution exceeds the query timeout value set and only the statement is rolled back
TransactionRequiredException:
if a lock mode other than NONE has been set and there is no transaction or the persistence context has not been joined to the transaction
PessimisticLockException:
if pessimistic locking fails and the transaction is rolled back
LockTimeoutException:
if pessimistic locking fails and only the statement is rolled back
PersistenceException:
if the query execution exceeds the query timeout value set and the transaction is rolled back
Since
2.2
See Also
Stream, getResultList()
getSingleResultback to summary
public X getSingleResult()

Redeclares jakarta.persistence.Query.getSingleResult.

Execute a SELECT query that returns a single result.

Returns:X

the result

Exceptions
NoResultException:
if there is no result
NonUniqueResultException:
if more than one result
IllegalStateException:
if called for a Jakarta Persistence query language UPDATE or DELETE statement
QueryTimeoutException:
if the query execution exceeds the query timeout value set and only the statement is rolled back
TransactionRequiredException:
if a lock mode other than NONE has been set and there is no transaction or the persistence context has not been joined to the transaction
PessimisticLockException:
if pessimistic locking fails and the transaction is rolled back
LockTimeoutException:
if pessimistic locking fails and only the statement is rolled back
PersistenceException:
if the query execution exceeds the query timeout value set and the transaction is rolled back
setFirstResultback to summary
public TypedQuery<X> setFirstResult(int startPosition)

Redeclares jakarta.persistence.Query.setFirstResult.

Set the position of the first result to retrieve.

Parameters
startPosition:int

position of the first result, numbered from 0

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if the argument is negative
setFlushModeback to summary
public TypedQuery<X> setFlushMode(FlushModeType flushMode)

Redeclares jakarta.persistence.Query.setFlushMode.

Set the flush mode type to be used for the query execution. The flush mode type applies to the query regardless of the flush mode type in use for the entity manager.

Parameters
flushMode:FlushModeType

flush mode

Returns:TypedQuery<X>

the same query instance

setHintback to summary
public TypedQuery<X> setHint(String hintName, Object value)

Redeclares jakarta.persistence.Query.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:String

name of property or hint

value:Object

value for the property or hint

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if the second argument is not valid for the implementation
setLockModeback to summary
public TypedQuery<X> setLockMode(LockModeType lockMode)

Redeclares jakarta.persistence.Query.setLockMode.

Set the lock mode type to be used for the query execution.

Parameters
lockMode:LockModeType

lock mode

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalStateException:
if the query is found not to be a Jakarta Persistence query language SELECT query or a CriteriaQuery query
setMaxResultsback to summary
public TypedQuery<X> setMaxResults(int maxResult)

Redeclares jakarta.persistence.Query.setMaxResults.

Set the maximum number of results to retrieve.

Parameters
maxResult:int

maximum number of results to retrieve

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if the argument is negative
setParameterback to summary
public <T> TypedQuery<X> setParameter(Parameter<T> param, T value)

Redeclares jakarta.persistence.Query.setParameter.

Bind the value of a Parameter object.

Parameters
param:Parameter<T>

parameter object

value:T

parameter value

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if the parameter does not correspond to a parameter of the query
setParameterback to summary
public TypedQuery<X> setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Calendar to a Parameter object.

Parameters
param:Parameter<Calendar>

parameter object

value:Calendar

parameter value

temporalType:TemporalType

temporal type

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if the parameter does not correspond to a parameter of the query
setParameterback to summary
public TypedQuery<X> setParameter(Parameter<Date> param, Date value, TemporalType temporalType)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Date to a Parameter object.

Parameters
param:Parameter<Date>

parameter object

value:Date

parameter value

temporalType:TemporalType

temporal type

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if the parameter does not correspond to a parameter of the query
setParameterback to summary
public TypedQuery<X> setParameter(String name, Object value)

Redeclares jakarta.persistence.Query.setParameter.

Bind an argument value to a named parameter.

Parameters
name:String

parameter name

value:Object

parameter value

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if the parameter name does not correspond to a parameter of the query or if the argument is of incorrect type
setParameterback to summary
public TypedQuery<X> setParameter(String name, Calendar value, TemporalType temporalType)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Calendar to a named parameter.

Parameters
name:String

parameter name

value:Calendar

parameter value

temporalType:TemporalType

temporal type

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if the parameter name does not correspond to a parameter of the query or if the value argument is of incorrect type
setParameterback to summary
public TypedQuery<X> setParameter(String name, Date value, TemporalType temporalType)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Date to a named parameter.

Parameters
name:String

parameter name

value:Date

parameter value

temporalType:TemporalType

temporal type

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if the parameter name does not correspond to a parameter of the query or if the value argument is of incorrect type
setParameterback to summary
public TypedQuery<X> setParameter(int position, Object value)

Redeclares jakarta.persistence.Query.setParameter.

Bind an argument value to a positional parameter.

Parameters
position:int

position

value:Object

parameter value

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if position does not correspond to a positional parameter of the query or if the argument is of incorrect type
setParameterback to summary
public TypedQuery<X> setParameter(int position, Calendar value, TemporalType temporalType)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Calendar to a positional parameter.

Parameters
position:int

position

value:Calendar

parameter value

temporalType:TemporalType

temporal type

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if position does not correspond to a positional parameter of the query or if the value argument is of incorrect type
setParameterback to summary
public TypedQuery<X> setParameter(int position, Date value, TemporalType temporalType)

Redeclares jakarta.persistence.Query.setParameter.

Bind an instance of java.util.Date to a positional parameter.

Parameters
position:int

position

value:Date

parameter value

temporalType:TemporalType

temporal type

Returns:TypedQuery<X>

the same query instance

Exceptions
IllegalArgumentException:
if position does not correspond to a positional parameter of the query or if the value argument is of incorrect type