javax.persistence
Interface Query


public interface Query

Interface used to control query execution.

Since:
Java Persistence 1.0

Method Summary
 int executeUpdate()
          Execute an update or delete statement.
 java.util.List getResultList()
          Execute a SELECT query and return the query results as a List.
 java.lang.Object getSingleResult()
          Execute a SELECT query that returns a single result.
 Query setFirstResult(int startPosition)
          Set the position of the first result to retrieve.
 Query setFlushMode(FlushModeType flushMode)
          Set the flush mode type to be used for the query execution.
 Query setHint(java.lang.String hintName, java.lang.Object value)
          Set an implementation-specific hint.
 Query setMaxResults(int maxResult)
          Set the maximum number of results to retrieve.
 Query setParameter(int position, java.util.Calendar value, TemporalType temporalType)
          Bind an instance of java.util.Calendar to a positional parameter.
 Query setParameter(int position, java.util.Date value, TemporalType temporalType)
          Bind an instance of java.util.Date to a positional parameter.
 Query setParameter(int position, java.lang.Object value)
          Bind an argument to a positional parameter.
 Query setParameter(java.lang.String name, java.util.Calendar value, TemporalType temporalType)
          Bind an instance of java.util.Calendar to a named parameter.
 Query setParameter(java.lang.String name, java.util.Date value, TemporalType temporalType)
          Bind an instance of java.util.Date to a named parameter.
 Query setParameter(java.lang.String name, java.lang.Object value)
          Bind an argument to a named parameter.
 

Method Detail

getResultList

java.util.List getResultList()
Execute a SELECT query and return the query results as a List.

Returns:
a list of the results
Throws:
java.lang.IllegalStateException - if called for a Java Persistence query language UPDATE or DELETE statement

getSingleResult

java.lang.Object getSingleResult()
Execute a SELECT query that returns a single result.

Returns:
the result
Throws:
EntityNotFoundException - if there is no result
NonUniqueResultException - if more than one result
java.lang.IllegalStateException - if called for a Java Persistence query language UPDATE or DELETE statement

executeUpdate

int executeUpdate()
Execute an update or delete statement.

Returns:
the number of entities updated or deleted
Throws:
java.lang.IllegalStateException - if called for a Java Persistence query language SELECT statement
TransactionRequiredException - if there is no transaction

setMaxResults

Query setMaxResults(int maxResult)
Set the maximum number of results to retrieve.

Parameters:
maxResult -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if argument is negative

setFirstResult

Query setFirstResult(int startPosition)
Set the position of the first result to retrieve.

Parameters:
startPosition - the start position of the first result, numbered from 0
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if argument is negative

setHint

Query setHint(java.lang.String hintName,
              java.lang.Object value)
Set an implementation-specific hint. If the hint name is not recognized, it is silently ignored.

Parameters:
hintName -
value -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if the second argument is not valid for the implementation

setParameter

Query setParameter(java.lang.String name,
                   java.lang.Object value)
Bind an argument to a named parameter.

Parameters:
name - the parameter name
value -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if parameter name does not correspond to parameter in query string or argument is of incorrect type

setParameter

Query setParameter(java.lang.String name,
                   java.util.Date value,
                   TemporalType temporalType)
Bind an instance of java.util.Date to a named parameter.

Parameters:
name -
value -
temporalType -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if parameter name does not correspond to parameter in query string

setParameter

Query setParameter(java.lang.String name,
                   java.util.Calendar value,
                   TemporalType temporalType)
Bind an instance of java.util.Calendar to a named parameter.

Parameters:
name -
value -
temporalType -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if parameter name does not correspond to parameter in query string

setParameter

Query setParameter(int position,
                   java.lang.Object value)
Bind an argument to a positional parameter.

Parameters:
position -
value -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if position does not correspond to positional parameter of query or argument is of incorrect type

setParameter

Query setParameter(int position,
                   java.util.Date value,
                   TemporalType temporalType)
Bind an instance of java.util.Date to a positional parameter.

Parameters:
position -
value -
temporalType -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if position does not correspond to positional parameter of query

setParameter

Query setParameter(int position,
                   java.util.Calendar value,
                   TemporalType temporalType)
Bind an instance of java.util.Calendar to a positional parameter.

Parameters:
position -
value -
temporalType -
Returns:
the same query instance
Throws:
java.lang.IllegalArgumentException - if position does not correspond to positional parameter of query

setFlushMode

Query 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.

Parameters:
flushMode -