-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description List<X>
getResultList()
Execute a SELECT query and return the query results as a typed List.X
getSingleResult()
Execute a SELECT query that returns a single result.TypedQuery<X>
setFirstResult(int startPosition)
Set the position of the first result to retrieve.TypedQuery<X>
setFlushMode(FlushModeType flushMode)
Set the flush mode type to be used for the query execution.TypedQuery<X>
setHint(String hintName, Object value)
Set a query property or hint.TypedQuery<X>
setLockMode(LockModeType lockMode)
Set the lock mode type to be used for the query execution.TypedQuery<X>
setMaxResults(int maxResult)
Set the maximum number of results to retrieve.TypedQuery<X>
setParameter(int position, Calendar value, TemporalType temporalType)
Bind an instance ofjava.util.Calendar
to a positional parameter.TypedQuery<X>
setParameter(int position, Date value, TemporalType temporalType)
Bind an instance ofjava.util.Date
to a positional parameter.TypedQuery<X>
setParameter(int position, Object value)
Bind an argument value to a positional parameter.TypedQuery<X>
setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
Bind an instance ofjava.util.Calendar
to aParameter
object.TypedQuery<X>
setParameter(Parameter<Date> param, Date value, TemporalType temporalType)
Bind an instance ofjava.util.Date
to aParameter
object.<T> TypedQuery<X>
setParameter(Parameter<T> param, T value)
Bind the value of aParameter
object.TypedQuery<X>
setParameter(String name, Calendar value, TemporalType temporalType)
Bind an instance ofjava.util.Calendar
to a named parameter.TypedQuery<X>
setParameter(String name, Date value, TemporalType temporalType)
Bind an instance ofjava.util.Date
to a named parameter.TypedQuery<X>
setParameter(String name, Object value)
Bind an argument value to a named parameter.-
Methods inherited from interface javax.persistence.Query
executeUpdate, getFirstResult, getFlushMode, getHints, getLockMode, getMaxResults, getParameter, getParameter, getParameter, getParameter, getParameters, getParameterValue, getParameterValue, getParameterValue, isBound, unwrap
-
-
-
-
Method Detail
-
getResultList
List<X> getResultList()
Execute a SELECT query and return the query results as a typed List.- Specified by:
getResultList
in interfaceQuery
- Returns:
- a list of the results
- Throws:
IllegalStateException
- if called for a Java 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 thanNONE
has 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 back
-
getSingleResult
X getSingleResult()
Execute a SELECT query that returns a single result.- Specified by:
getSingleResult
in interfaceQuery
- Returns:
- the result
- Throws:
NoResultException
- if there is no resultNonUniqueResultException
- if more than one resultIllegalStateException
- if called for a Java 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 thanNONE
has 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 back
-
setMaxResults
TypedQuery<X> setMaxResults(int maxResult)
Set the maximum number of results to retrieve.- Specified by:
setMaxResults
in interfaceQuery
- Parameters:
maxResult
- maximum number of results to retrieve- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the argument is negative
-
setFirstResult
TypedQuery<X> setFirstResult(int startPosition)
Set the position of the first result to retrieve.- Specified by:
setFirstResult
in interfaceQuery
- Parameters:
startPosition
- position of the first result, numbered from 0- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the argument is negative
-
setHint
TypedQuery<X> setHint(String hintName, Object value)
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.- Specified by:
setHint
in interfaceQuery
- Parameters:
hintName
- name of property or hintvalue
- value for the property or hint- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the second argument is not valid for the implementation
-
setParameter
<T> TypedQuery<X> setParameter(Parameter<T> param, T value)
Bind the value of aParameter
object.- Specified by:
setParameter
in interfaceQuery
- Parameters:
param
- parameter objectvalue
- parameter value- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the parameter does not correspond to a parameter of the query
-
setParameter
TypedQuery<X> setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
Bind an instance ofjava.util.Calendar
to aParameter
object.- Specified by:
setParameter
in interfaceQuery
- Parameters:
param
- parameter objectvalue
- parameter valuetemporalType
- temporal type- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the parameter does not correspond to a parameter of the query
-
setParameter
TypedQuery<X> setParameter(Parameter<Date> param, Date value, TemporalType temporalType)
Bind an instance ofjava.util.Date
to aParameter
object.- Specified by:
setParameter
in interfaceQuery
- Parameters:
param
- parameter objectvalue
- parameter valuetemporalType
- temporal type- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if the parameter does not correspond to a parameter of the query
-
setParameter
TypedQuery<X> setParameter(String name, Object value)
Bind an argument value to a named parameter.- Specified by:
setParameter
in interfaceQuery
- Parameters:
name
- parameter namevalue
- parameter value- 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 incorrect type
-
setParameter
TypedQuery<X> setParameter(String name, Calendar value, TemporalType temporalType)
Bind an instance ofjava.util.Calendar
to a named parameter.- Specified by:
setParameter
in interfaceQuery
- Parameters:
name
- parameter namevalue
- parameter valuetemporalType
- 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 incorrect type
-
setParameter
TypedQuery<X> setParameter(String name, Date value, TemporalType temporalType)
Bind an instance ofjava.util.Date
to a named parameter.- Specified by:
setParameter
in interfaceQuery
- Parameters:
name
- parameter namevalue
- parameter valuetemporalType
- 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 incorrect type
-
setParameter
TypedQuery<X> setParameter(int position, Object value)
Bind an argument value to a positional parameter.- Specified by:
setParameter
in interfaceQuery
- Parameters:
position
- positionvalue
- parameter value- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if position does not correspond to a positional parameter of the query or if the argument is of incorrect type
-
setParameter
TypedQuery<X> setParameter(int position, Calendar value, TemporalType temporalType)
Bind an instance ofjava.util.Calendar
to a positional parameter.- Specified by:
setParameter
in interfaceQuery
- Parameters:
position
- positionvalue
- parameter valuetemporalType
- temporal type- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if position does not correspond to a positional parameter of the query or if the value argument is of incorrect type
-
setParameter
TypedQuery<X> setParameter(int position, Date value, TemporalType temporalType)
Bind an instance ofjava.util.Date
to a positional parameter.- Specified by:
setParameter
in interfaceQuery
- Parameters:
position
- positionvalue
- parameter valuetemporalType
- temporal type- Returns:
- the same query instance
- Throws:
IllegalArgumentException
- if position does not correspond to a positional parameter of the query or if the value argument is of incorrect type
-
setFlushMode
TypedQuery<X> setFlushMode(FlushModeType flushMode)
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.- Specified by:
setFlushMode
in interfaceQuery
- Parameters:
flushMode
- flush mode- Returns:
- the same query instance
-
setLockMode
TypedQuery<X> setLockMode(LockModeType lockMode)
Set the lock mode type to be used for the query execution.- Specified by:
setLockMode
in interfaceQuery
- Parameters:
lockMode
- lock mode- Returns:
- the same query instance
- Throws:
IllegalStateException
- if the query is found not to be a Java Persistence query language SELECT query or a CriteriaQuery query
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/persistence/TypedQuery.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.