Top Description Methods
org.hibernate.annotations

public @Interface NamedQuery

extends Annotation
Annotations
@Target:TYPE, PACKAGE
@Retention:RUNTIME
@Repeatable:NamedQueries
Imports
java.lang.annotation.Repeatable, .Retention, .Target, jakarta.persistence.CacheRetrieveMode, .CacheStoreMode, org.hibernate.Remove

Declares a named query written in HQL or JPQL.

Whereas jakarta.persistence.NamedQuery allows settings to be specified using stringly-typed jakarta.persistence.QueryHints, this annotation is typesafe.

Note that the members of this annotation correspond to hints enumerated by org.hibernate.jpa.AvailableHints.

Author
Carlos Gonzalez-Cadenas
See Also
org.hibernate.query.Query

Method Summary

Modifier and TypeMethod and Description
public boolean
cacheable()

Whether the query results are cacheable.

public @Remove CacheModeType
cacheMode()

Deprecated since 6.2. use cacheStoreMode() and cacheRetrieveMode() since CacheModeType is deprecated
The cache interaction mode for this query.
public String
cacheRegion()

If the query results are cacheable, the name of the query cache region.

public CacheRetrieveMode
cacheRetrieveMode()

The cache retrieval mode for objects returned by this query.

public CacheStoreMode
cacheStoreMode()

The cache storage mode for objects returned by this query.

public String
comment()

A comment added to the generated SQL query.

public int
fetchSize()

The number of rows fetched by the JDBC driver per trip.

public FlushModeType
flushMode()

The flush mode for this query.

public String
name()

The name of this query.

public String
query()

The text of the HQL query.

public boolean
readOnly()

Whether the results should be loaded in read-only mode.

public int
timeout()

The query timeout in seconds.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

cacheableback to summary
public boolean cacheable()

Whether the query results are cacheable. Default is false, that is, not cacheable.

See Also
org.hibernate.query.SelectionQuery#setCacheable(boolean), org.hibernate.jpa.HibernateHints#HINT_CACHEABLE
cacheModeback to summary
public @Remove CacheModeType cacheMode()

Deprecated

since 6.2.

use cacheStoreMode() and cacheRetrieveMode() since CacheModeType is deprecated

The cache interaction mode for this query.

Annotations
@Deprecated
since:6.2
@Remove
See Also
org.hibernate.jpa.HibernateHints#HINT_CACHE_MODE
cacheRegionback to summary
public String cacheRegion()

If the query results are cacheable, the name of the query cache region.

See Also
org.hibernate.query.SelectionQuery#setCacheRegion(String), org.hibernate.jpa.HibernateHints#HINT_CACHE_REGION
cacheRetrieveModeback to summary
public CacheRetrieveMode cacheRetrieveMode()

The cache retrieval mode for objects returned by this query.

See Also
org.hibernate.query.Query#setCacheRetrieveMode(CacheRetrieveMode), org.hibernate.jpa.SpecHints#HINT_SPEC_CACHE_RETRIEVE_MODE
cacheStoreModeback to summary
public CacheStoreMode cacheStoreMode()

The cache storage mode for objects returned by this query.

See Also
org.hibernate.query.Query#setCacheStoreMode(CacheStoreMode), org.hibernate.jpa.SpecHints#HINT_SPEC_CACHE_STORE_MODE
commentback to summary
public String comment()

A comment added to the generated SQL query. Useful when engaging with DBA.

See Also
org.hibernate.query.CommonQueryContract#setComment(String), org.hibernate.jpa.HibernateHints#HINT_COMMENT
fetchSizeback to summary
public int fetchSize()

The number of rows fetched by the JDBC driver per trip.

See Also
org.hibernate.query.SelectionQuery#setFetchSize(int), org.hibernate.jpa.HibernateHints#HINT_FETCH_SIZE
flushModeback to summary
public FlushModeType flushMode()

The flush mode for this query.

See Also
org.hibernate.query.CommonQueryContract#setFlushMode(jakarta.persistence.FlushModeType), org.hibernate.jpa.HibernateHints#HINT_FLUSH_MODE
nameback to summary
public String name()

The name of this query. Must be unique within a persistence unit.

queryback to summary
public String query()

The text of the HQL query.

readOnlyback to summary
public boolean readOnly()

Whether the results should be loaded in read-only mode. Default is false.

See Also
org.hibernate.query.SelectionQuery#setReadOnly(boolean), org.hibernate.jpa.HibernateHints#HINT_READ_ONLY
timeoutback to summary
public int timeout()

The query timeout in seconds. Default is no timeout.

See Also
org.hibernate.query.CommonQueryContract#setTimeout(int), org.hibernate.jpa.HibernateHints#HINT_TIMEOUT, org.hibernate.jpa.SpecHints#HINT_SPEC_QUERY_TIMEOUT