For most queries, including criteria queries, the query cache is not efficient because query cache invalidation occurs too frequently. However, there is a special kind of query where you can optimize the cache invalidation algorithm: lookups by a constant natural key. In some applications, this kind of query occurs frequently. The criteria API provides special provision for this use case.
First, map the natural key of your entity using
<natural-id> and enable use of the second-level cache.
This functionality is not intended for use with entities with mutable natural keys.
Once you have enabled the Hibernate query cache, the
Restrictions.naturalId() allows you to make use of the more efficient cache algorithm.