Package org.hibernate.query
Interface CommonQueryContract
-
- All Known Subinterfaces:
HqlQueryImplementor<R>
,NativeQuery<T>
,NativeQueryImplementor<R>
,ProcedureCall
,ProcedureCallImplementor<R>
,Query<R>
,QueryImplementor<R>
- All Known Implementing Classes:
AbstractQuery
public interface CommonQueryContract
Defines the aspects of query definition that apply to all forms of querying (HQL, JPQL, criteria) across all forms of persistence contexts (Session, StatelessSession, EntityManager).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CacheMode
getCacheMode()
Obtain the CacheMode in effect for this query.String
getCacheRegion()
Obtain the name of the second level query cache region in which query results will be stored (if they are cached, see the discussion onisCacheable()
for more information).Integer
getFetchSize()
Obtain the JDBC fetch size hint in effect for this query.FlushMode
getHibernateFlushMode()
Obtain the FlushMode in effect for this query.Integer
getTimeout()
Obtain the query timeout in seconds.boolean
isCacheable()
Are the results of this query eligible for second level query caching?boolean
isReadOnly()
Should entities and proxies loaded by this Query be put in read-only mode? If the read-only/modifiable setting was not initialized, then the default read-only/modifiable setting for the persistence context is returned instead.CommonQueryContract
setCacheable(boolean cacheable)
Enable/disable second level query (result) caching for this query.CommonQueryContract
setCacheMode(CacheMode cacheMode)
(Re)set the current CacheMode in effect for this query.CommonQueryContract
setCacheRegion(String cacheRegion)
Set the name of the cache region where query results should be cached (if cached at all).CommonQueryContract
setFetchSize(int fetchSize)
Sets a JDBC fetch size hint for the query.CommonQueryContract
setHibernateFlushMode(FlushMode flushMode)
(Re)set the current FlushMode in effect for this query.CommonQueryContract
setReadOnly(boolean readOnly)
Set the read-only/modifiable mode for entities and proxies loaded by this Query.CommonQueryContract
setTimeout(int timeout)
Set the query timeout in seconds.
-
-
-
Method Detail
-
getHibernateFlushMode
FlushMode getHibernateFlushMode()
Obtain the FlushMode in effect for this query. By default, the query inherits the FlushMode of the Session from which it originates.- Returns:
- The query FlushMode.
- See Also:
Session.getHibernateFlushMode()
,FlushMode
-
setHibernateFlushMode
CommonQueryContract setHibernateFlushMode(FlushMode flushMode)
(Re)set the current FlushMode in effect for this query.- Parameters:
flushMode
- The new FlushMode to use.- Returns:
this
, for method chaining- See Also:
Session.getHibernateFlushMode()
,getHibernateFlushMode()
-
getCacheMode
CacheMode getCacheMode()
Obtain the CacheMode in effect for this query. By default, the query inherits the CacheMode of the Session from which is originates. NOTE: The CacheMode here describes reading-from/writing-to the entity/collection caches as we process query results. For caching of the actual (unparsed) query results, seeisCacheable()
andgetCacheRegion()
In order for this setting to have any affect, second-level caching would have to be enabled and the entities/collections in question configured for caching.- Returns:
- The query CacheMode.
- See Also:
Session.getCacheMode()
,CacheMode
-
setCacheMode
CommonQueryContract setCacheMode(CacheMode cacheMode)
(Re)set the current CacheMode in effect for this query.- Parameters:
cacheMode
- The new CacheMode to use.- Returns:
this
, for method chaining- See Also:
getCacheMode()
-
isCacheable
boolean isCacheable()
Are the results of this query eligible for second level query caching? This is different that second level caching of any returned entities and collections, which is controlled bygetCacheMode()
. NOTE: the query being "eligible" for caching does not necessarily mean its results will be cached. Second level query caching still has to be enabled on theSessionFactory
for this to happen. Usually that is controlled by thehibernate.cache.use_query_cache
configuration setting.- Returns:
true
if the query results are eligible for caching,false
otherwise.- See Also:
AvailableSettings.USE_QUERY_CACHE
-
setCacheable
CommonQueryContract setCacheable(boolean cacheable)
Enable/disable second level query (result) caching for this query.- Parameters:
cacheable
- Should the query results be cacheable?- Returns:
this
, for method chaining- See Also:
isCacheable()
-
getCacheRegion
String getCacheRegion()
Obtain the name of the second level query cache region in which query results will be stored (if they are cached, see the discussion onisCacheable()
for more information).null
indicates that the default region should be used.- Returns:
- The specified cache region name into which query results should be placed;
null
indicates the default region.
-
setCacheRegion
CommonQueryContract setCacheRegion(String cacheRegion)
Set the name of the cache region where query results should be cached (if cached at all).- Parameters:
cacheRegion
- the name of a query cache region, ornull
to indicate that the default region should be used.- Returns:
this
, for method chaining- See Also:
getCacheRegion()
-
getTimeout
Integer getTimeout()
Obtain the query timeout in seconds. This value is eventually passed along to the JDBC query viaStatement.setQueryTimeout(int)
. Zero indicates no timeout.- Returns:
- The timeout in seconds
- See Also:
Statement.getQueryTimeout()
,Statement.setQueryTimeout(int)
-
setTimeout
CommonQueryContract setTimeout(int timeout)
Set the query timeout in seconds. NOTE it is important to understand that any value set here is eventually passed directly through to the JDBC Statement which expressly disallows negative values. So negative values should be avoided as a general rule.- Parameters:
timeout
- the timeout in seconds- Returns:
this
, for method chaining- See Also:
getTimeout()
-
getFetchSize
Integer getFetchSize()
Obtain the JDBC fetch size hint in effect for this query. This value is eventually passed along to the JDBC query viaStatement.setFetchSize(int)
. As defined b y JDBC, this value is a hint to the driver to indicate how many rows to fetch from the database when more rows are needed. NOTE : JDBC expressly defines this value as a hint. It may or may not have any effect on the actual query execution and ResultSet processing depending on the driver.- Returns:
- The timeout in seconds
- See Also:
Statement.getFetchSize()
,Statement.setFetchSize(int)
-
setFetchSize
CommonQueryContract setFetchSize(int fetchSize)
Sets a JDBC fetch size hint for the query.- Parameters:
fetchSize
- the fetch size hint- Returns:
this
, for method chaining- See Also:
getFetchSize()
-
isReadOnly
boolean isReadOnly()
Should entities and proxies loaded by this Query be put in read-only mode? If the read-only/modifiable setting was not initialized, then the default read-only/modifiable setting for the persistence context is returned instead.- Returns:
true
if the entities and proxies loaded by the query will be put in read-only mode;false
otherwise (they will be modifiable)- See Also:
setReadOnly(boolean)
,The read-only/modifiable setting has no impact on entities/proxies returned by the query that existed in the session beforeQuery the query was executed.
-
setReadOnly
CommonQueryContract setReadOnly(boolean readOnly)
Set the read-only/modifiable mode for entities and proxies loaded by this Query. This setting overrides the default setting for the persistence context.- Parameters:
readOnly
-true
indicates that entities and proxies loaded by the query are to be put in read-only mode;false
indicates that entities and proxies loaded by the query will be put in modifiable mode- Returns:
this
, for method chaining- See Also:
To 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 beforeQuery the query was executed.
-
-