«Top»

On the previous parts of our
series on software caches in Java application servers,
we focused on an example application using caches as a simple, stand-alone, temporary data store.

However, Caches may also be used as DB Caches in JEE or Spring applications.

This page exemplifies this by giving a short overview of
how to integrate Java Caches as a Second Level Cache with
Hibernate.

Hibernate serves as an example here,
Java caches typically support other database integrations as well.

Obviously, caches should be deployed in a consistent mode when used as
Hibernate caches.

Hibernate’s second level cache is well described in Section 2.1. of
this guide,
which is about
JBoss Cache integration.

As shown there, Hibernate’s second level cache handles four different types
of data:

  • Entities
  • Collections
  • Query results
  • Timestamps

Hibernate’s second level cache must implement the interface
org.hibernate.cache.RegionFactory
which defines methods for each of these types.

All three Java Caches presented in our series provide a RegionFactory implementation:

In Hibernate, the RegionFactory implementation can be configured in
hibernate.cfg.xml.

As a result, the cache becomes available as a Hibernate Second Level Cache
without any code changes.

Next

The final page of our series provides a list of advanced features of
Java caches: