O'Reilly logo

JBoss AS 7 Configuration, Deployment, and Administration by Francesco Marchioni

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Caching queries

The query cache can be used to cache data from a query so that if the same query is issued again, it will not hit the database but return the cached value.

Note

Note that 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 value type.

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

@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") private String name; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required