Book Image

WildFly Configuration, Deployment, and Administration

By : Francesco Marchioni, Christopher Adam M Ritchie
Book Image

WildFly Configuration, Deployment, and Administration

By: Francesco Marchioni, Christopher Adam M Ritchie

Overview of this book

Table of Contents (19 chapters)
WildFly Configuration, Deployment, and Administration Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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

...
}

Note

Overuse of the query cache may reduce your application's performance, so use it wisely. First, the query cache will increase the memory requirements if your queries (stored as key in the query cache map) are made up...