Caching queries

The query cache can be used to cache the result set of a query. This means that if the same query is issued again, it will not hit the database but return the cached value.

Note

The query cache does not cache the state of the actual entities in the result set; it caches only the identifier values and results of the value type.

In the following example, the query result set named listUsers is configured to be cached using the @QueryHint annotation inside a @NamedQuery annotation:

@NamedQueries( { @NamedQuery( name = "listUsers", query = "FROM User c WHERE c.name = :name", hints = { @QueryHint(name = "org.hibernate.cacheable", value = "true") } ) }) public class User { @Id @Column(name="key") private String key; @Column(name="name") ...

Get WildFly Configuration, Deployment, and Administration - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.