public interface Query extends BasicQueryContract
Modifier and Type | Method and Description |
---|---|
Query |
addQueryHint(String hint)
Add a DB query hint to the SQL.
|
int |
executeUpdate()
Execute the update or delete statement.
|
String |
getComment()
Obtain the comment currently associated with this query.
|
Integer |
getFirstResult()
Obtain the value specified (if any) for the first row to be returned from the query results; zero-based.
|
LockOptions |
getLockOptions()
Obtains the LockOptions in effect for this query.
|
Integer |
getMaxResults()
Obtains the limit set on the maximum number of rows to retrieve.
|
String[] |
getNamedParameters()
Return the names of all named parameters of the query.
|
String |
getQueryString()
Get the query string.
|
String[] |
getReturnAliases()
Return the HQL select clause aliases, if any.
|
Iterator |
iterate()
Return the query results as an Iterator.
|
List |
list()
Return the query results as a List.
|
ScrollableResults |
scroll()
Return the query results as ScrollableResults.
|
ScrollableResults |
scroll(ScrollMode scrollMode)
Return the query results as ScrollableResults.
|
Query |
setBigDecimal(int position,
BigDecimal number)
Bind a positional BigDecimal-valued parameter.
|
Query |
setBigDecimal(String name,
BigDecimal number)
Bind a named BigDecimal-valued parameter.
|
Query |
setBigInteger(int position,
BigInteger number)
Bind a positional BigDecimal-valued parameter.
|
Query |
setBigInteger(String name,
BigInteger number)
Bind a named BigInteger-valued parameter.
|
Query |
setBinary(int position,
byte[] val)
Bind a positional binary-valued parameter.
|
Query |
setBinary(String name,
byte[] val)
Bind a named binary-valued parameter.
|
Query |
setBoolean(int position,
boolean val)
Bind a positional boolean-valued parameter.
|
Query |
setBoolean(String name,
boolean val)
Bind a named boolean-valued parameter.
|
Query |
setByte(int position,
byte val)
Bind a positional byte-valued parameter.
|
Query |
setByte(String name,
byte val)
Bind a named byte-valued parameter.
|
Query |
setCacheable(boolean cacheable)
Enable/disable second level query (result) caching for this query.
|
Query |
setCacheMode(CacheMode cacheMode)
(Re)set the current CacheMode in effect for this query.
|
Query |
setCacheRegion(String cacheRegion)
Set the name of the cache region where query results should be cached (if cached at all).
|
Query |
setCalendar(int position,
Calendar calendar)
Bind a positional Calendar-valued parameter using the full Timestamp portion.
|
Query |
setCalendar(String name,
Calendar calendar)
Bind a named Calendar-valued parameter using the full Timestamp.
|
Query |
setCalendarDate(int position,
Calendar calendar)
Bind a positional Calendar-valued parameter using just the Date portion.
|
Query |
setCalendarDate(String name,
Calendar calendar)
Bind a named Calendar-valued parameter using just the Date portion.
|
Query |
setCharacter(int position,
char val)
Bind a positional char-valued parameter.
|
Query |
setCharacter(String name,
char val)
Bind a named char-valued parameter.
|
Query |
setComment(String comment)
Set the comment for this query.
|
Query |
setDate(int position,
Date date)
Bind a positional Date-valued parameter using just the Date portion.
|
Query |
setDate(String name,
Date date)
Bind the date (time is truncated) of a given Date object to a named query parameter.
|
Query |
setDouble(int position,
double val)
Bind a positional double-valued parameter.
|
Query |
setDouble(String name,
double val)
Bind a named double-valued parameter.
|
Query |
setEntity(int position,
Object val)
Bind an instance of a mapped persistent class to a JDBC-style query parameter.
|
Query |
setEntity(String name,
Object val)
Bind an instance of a mapped persistent class to a named query parameter.
|
Query |
setFetchSize(int fetchSize)
Sets a JDBC fetch size hint for the query.
|
Query |
setFirstResult(int firstResult)
Set the first row to retrieve.
|
Query |
setFloat(int position,
float val)
Bind a positional float-valued parameter.
|
Query |
setFloat(String name,
float val)
Bind a named float-valued parameter.
|
Query |
setFlushMode(FlushMode flushMode)
(Re)set the current FlushMode in effect for this query.
|
Query |
setInteger(int position,
int val)
Bind a positional int-valued parameter.
|
Query |
setInteger(String name,
int val)
Bind a named int-valued parameter.
|
Query |
setLocale(int position,
Locale locale)
Bind a positional Locale-valued parameter.
|
Query |
setLocale(String name,
Locale locale)
Bind a named Locale-valued parameter.
|
Query |
setLockMode(String alias,
LockMode lockMode)
Set the LockMode to use for specific alias (as defined in the query's FROM clause).
|
Query |
setLockOptions(LockOptions lockOptions)
Set the lock options for the query.
|
Query |
setLong(int position,
long val)
Bind a positional long-valued parameter.
|
Query |
setLong(String name,
long val)
Bind a named long-valued parameter.
|
Query |
setMaxResults(int maxResults)
Set the maximum number of rows to retrieve.
|
Query |
setParameter(int position,
Object val)
Bind a value to a JDBC-style query parameter.
|
Query |
setParameter(int position,
Object val,
Type type)
Bind a value to a JDBC-style query parameter.
|
Query |
setParameter(String name,
Object val)
Bind a value to a named query parameter.
|
Query |
setParameter(String name,
Object val,
Type type)
Bind a value to a named query parameter.
|
Query |
setParameterList(String name,
Collection values)
Bind multiple values to a named query parameter.
|
Query |
setParameterList(String name,
Collection values,
Type type)
Bind multiple values to a named query parameter.
|
Query |
setParameterList(String name,
Object[] values)
Bind multiple values to a named query parameter.
|
Query |
setParameterList(String name,
Object[] values,
Type type)
Bind multiple values to a named query parameter.
|
Query |
setParameters(Object[] values,
Type[] types)
Bind values and types to positional parameters.
|
Query |
setProperties(Map bean)
Bind the values of the given Map for each named parameters of the query,
matching key names with parameter names and mapping value types to
Hibernate types using heuristics.
|
Query |
setProperties(Object bean)
Bind the property values of the given bean to named parameters of the query,
matching property names with parameter names and mapping property types to
Hibernate types using heuristics.
|
Query |
setReadOnly(boolean readOnly)
Set the read-only/modifiable mode for entities and proxies
loaded by this Query.
|
Query |
setResultTransformer(ResultTransformer transformer)
Set a strategy for handling the query results.
|
Query |
setSerializable(int position,
Serializable val)
Bind a positional binary-valued parameter using serialization.
|
Query |
setSerializable(String name,
Serializable val)
Bind a named binary-valued parameter using serialization.
|
Query |
setShort(int position,
short val)
Bind a positional short-valued parameter.
|
Query |
setShort(String name,
short val)
Bind a named short-valued parameter.
|
Query |
setString(int position,
String val)
Bind a positional String-valued parameter.
|
Query |
setString(String name,
String val)
Bind a named String-valued parameter.
|
Query |
setText(int position,
String val)
Bind a positional String-valued parameter using streaming.
|
Query |
setText(String name,
String val)
Bind a named String-valued parameter using streaming.
|
Query |
setTime(int position,
Date date)
Bind a positional Date-valued parameter using just the Time portion.
|
Query |
setTime(String name,
Date date)
Bind the time (date is truncated) of a given Date object to a named query parameter.
|
Query |
setTimeout(int timeout)
Set the query timeout in seconds.
|
Query |
setTimestamp(int position,
Date date)
Bind a positional Date-valued parameter using the full Timestamp.
|
Query |
setTimestamp(String name,
Date date)
Bind the date and the time of a given Date object to a named query parameter.
|
Object |
uniqueResult()
Convenience method to return a single instance that matches
the query, or null if the query returns no results.
|
getCacheMode, getCacheRegion, getFetchSize, getFlushMode, getReturnTypes, getTimeout, isCacheable, isReadOnly
String getQueryString()
Integer getMaxResults()
null
and any negative values are interpreted as no
limit; however, this method should always return null in such case.Query setMaxResults(int maxResults)
maxResults
- the maximum number of rowsthis
, for method chaininggetMaxResults()
Integer getFirstResult()
getMaxResults()
in "paginated queries". No value specified means the first result
is returned. Zero and negative numbers are the same as no setting.Query setFirstResult(int firstResult)
firstResult
- a row number, numbered from 0this
, for method chaininggetFirstResult()
Query setFlushMode(FlushMode flushMode)
BasicQueryContract
setFlushMode
in interface BasicQueryContract
flushMode
- The new FlushMode to use.this
, for method chainingBasicQueryContract.getFlushMode()
Query setCacheMode(CacheMode cacheMode)
BasicQueryContract
setCacheMode
in interface BasicQueryContract
cacheMode
- The new CacheMode to use.this
, for method chainingBasicQueryContract.getCacheMode()
Query setCacheable(boolean cacheable)
BasicQueryContract
setCacheable
in interface BasicQueryContract
cacheable
- Should the query results be cacheable?this
, for method chainingBasicQueryContract.isCacheable()
Query setCacheRegion(String cacheRegion)
BasicQueryContract
setCacheRegion
in interface BasicQueryContract
cacheRegion
- the name of a query cache region, or null
to indicate that the default region
should be used.this
, for method chainingBasicQueryContract.getCacheRegion()
Query setTimeout(int timeout)
BasicQueryContract
setTimeout
in interface BasicQueryContract
timeout
- the timeout in secondsthis
, for method chainingBasicQueryContract.getTimeout()
Query setFetchSize(int fetchSize)
BasicQueryContract
setFetchSize
in interface BasicQueryContract
fetchSize
- the fetch size hintthis
, for method chainingBasicQueryContract.getFetchSize()
Query setReadOnly(boolean readOnly)
BasicQueryContract
setReadOnly
in interface BasicQueryContract
readOnly
- true, entities and proxies loaded by the query will be put in read-only mode
false, entities and proxies loaded by the query will be put in modifiable modethis
, for method chainingTo set the default read-only/modifiable setting used for
entities and proxies that are loaded into the session:
,
PersistenceContext.setDefaultReadOnly(boolean)
,
Read-only entities are not dirty-checked and snapshots of persistent
state are not maintained. Read-only entities can be modified, but
changes are not persisted.
When a proxy is initialized, the loaded entity will have the same
read-only/modifiable setting as the uninitialized
proxy has, regardless of the session's current setting.
The read-only/modifiable setting has no impact on entities/proxies
returned by the query that existed in the session before the query was executed.
LockOptions getLockOptions()
LockOptions
Query setLockOptions(LockOptions lockOptions)
setLockMode(String, LockMode)
.lockOptions
- The lock options to apply to the query.this
, for method chaininggetLockOptions()
Query setLockMode(String alias, LockMode lockMode)
LockOptions
.
The effect of these alias-specific LockModes is somewhat dependent on the driver/database in use. Generally
speaking, for maximum portability, this method should only be used to mark that the rows corresponding to
the given alias should be included in pessimistic locking (LockMode.PESSIMISTIC_WRITE
).alias
- a query alias, or "this"
for a collection filterlockMode
- The lock mode to apply.this
, for method chaininggetLockOptions()
String getComment()
hibernate.use_sql_comments
config setting), this comment will also be added
to the SQL query sent to the database. Often useful for identifying the source of troublesome queries on the
database side.Query setComment(String comment)
comment
- The human-readable commentthis
, for method chaininggetComment()
Query addQueryHint(String hint)
QueryHint
, which is specific
to the JPA implementation and ignores DB vendor-specific hints. Instead, these are intended solely for the
vendor-specific hints, such as Oracle's optimizers. Multiple query hints are supported; the Dialect will
determine concatenation and placement.hint
- The database specific query hint to add.String[] getReturnAliases()
String[] getNamedParameters()
Iterator iterate()
ScrollableResults scroll()
ScrollableResults
ScrollableResults scroll(ScrollMode scrollMode)
scrollMode
- The scroll modeScrollableResults
,
ScrollMode
List list()
Object uniqueResult()
NonUniqueResultException
- if there is more than one matching resultint executeUpdate()
Query setParameter(int position, Object val, Type type)
position
- the position of the parameter in the query
string, numbered from 0.val
- the possibly-null parameter valuetype
- the Hibernate typethis
, for method chainingQuery setParameter(String name, Object val, Type type)
name
- the name of the parameterval
- the possibly-null parameter valuetype
- the Hibernate typethis
, for method chainingQuery setParameter(int position, Object val)
position
- the position of the parameter in the query
string, numbered from 0.val
- the non-null parameter valuethis
, for method chainingQuery setParameter(String name, Object val)
name
- the name of the parameterval
- the non-null parameter valuethis
, for method chainingQuery setParameters(Object[] values, Type[] types)
types
- The typesvalues
- The valuesthis
, for method chainingQuery setParameterList(String name, Collection values, Type type)
name
- the name of the parametervalues
- a collection of values to listtype
- the Hibernate type of the valuesthis
, for method chainingQuery setParameterList(String name, Collection values)
name
- the name of the parametervalues
- a collection of values to listthis
, for method chainingQuery setParameterList(String name, Object[] values, Type type)
name
- the name of the parametervalues
- a collection of values to listtype
- the Hibernate type of the valuesthis
, for method chainingQuery setParameterList(String name, Object[] values)
name
- the name of the parametervalues
- a collection of values to listthis
, for method chainingQuery setProperties(Object bean)
bean
- any JavaBean or POJOthis
, for method chainingQuery setProperties(Map bean)
bean
- a java.util.Mapthis
, for method chainingQuery setString(int position, String val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setCharacter(int position, char val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setBoolean(int position, boolean val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setByte(int position, byte val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setShort(int position, short val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setInteger(int position, int val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setLong(int position, long val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setFloat(int position, float val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setDouble(int position, double val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setBinary(int position, byte[] val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setText(int position, String val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setSerializable(int position, Serializable val)
position
- The parameter positionval
- The bind valuethis
, for method chainingQuery setLocale(int position, Locale locale)
position
- The parameter positionlocale
- The bind valuethis
, for method chainingQuery setBigDecimal(int position, BigDecimal number)
position
- The parameter positionnumber
- The bind valuethis
, for method chainingQuery setBigInteger(int position, BigInteger number)
position
- The parameter positionnumber
- The bind valuethis
, for method chainingQuery setDate(int position, Date date)
position
- The parameter positiondate
- The bind valuethis
, for method chainingQuery setTime(int position, Date date)
position
- The parameter positiondate
- The bind valuethis
, for method chainingQuery setTimestamp(int position, Date date)
position
- The parameter positiondate
- The bind valuethis
, for method chainingQuery setCalendar(int position, Calendar calendar)
position
- The parameter positioncalendar
- The bind valuethis
, for method chainingQuery setCalendarDate(int position, Calendar calendar)
position
- The parameter positioncalendar
- The bind valuethis
, for method chainingQuery setString(String name, String val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setCharacter(String name, char val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setBoolean(String name, boolean val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setByte(String name, byte val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setShort(String name, short val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setInteger(String name, int val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setLong(String name, long val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setFloat(String name, float val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setDouble(String name, double val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setBinary(String name, byte[] val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setText(String name, String val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setSerializable(String name, Serializable val)
name
- The parameter nameval
- The bind valuethis
, for method chainingQuery setLocale(String name, Locale locale)
name
- The parameter namelocale
- The bind valuethis
, for method chainingQuery setBigDecimal(String name, BigDecimal number)
name
- The parameter namenumber
- The bind valuethis
, for method chainingQuery setBigInteger(String name, BigInteger number)
name
- The parameter namenumber
- The bind valuethis
, for method chainingQuery setDate(String name, Date date)
name
- The name of the parameterdate
- The date objectthis
, for method chainingQuery setTime(String name, Date date)
name
- The name of the parameterdate
- The date objectthis
, for method chainingQuery setTimestamp(String name, Date date)
name
- The name of the parameterdate
- The date objectthis
, for method chainingQuery setCalendar(String name, Calendar calendar)
name
- The parameter namecalendar
- The bind valuethis
, for method chainingQuery setCalendarDate(String name, Calendar calendar)
name
- The parameter namecalendar
- The bind valuethis
, for method chainingQuery setEntity(int position, Object val)
setParameter(int, Object)
for null values.position
- the position of the parameter in the query
string, numbered from 0.val
- a non-null instance of a persistent classthis
, for method chainingQuery setEntity(String name, Object val)
setParameter(String, Object)
for null values.name
- the name of the parameterval
- a non-null instance of a persistent classthis
, for method chainingQuery setResultTransformer(ResultTransformer transformer)
transformer
- The transformer to applyCopyright © 2001-2017 Red Hat, Inc. All Rights Reserved.