The key steps in using JBoss Cache as a second level cache are to:
Tell Hibernate in your SessionFactory
configuration that you want to use JBoss Cache 2 as your
Second Level Cache implementation:
hibernate.cache.region.factory_class= org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory
There are a number of values that can be provided for the
hibernate.cache.region.factory_class
property, depending on how you want the JBoss Cache integration
to work. Based on what factory class you specify, there are
additional detail configuration properties you can add to further
control that factory. However, simply specifying the
MultiplexedJBossCacheRegionFactory
shown
above provides a reasonable set of default values useful for
many applications. See Section 3.1.2, “Specifying the RegionFactory
Implementation”
for more details.
Do not set the legacy hibernate.cache.provider_class
property when using JBoss Cache 2. That is a legacy property
from before Hibernate 3.3's redesign of second level caching
internals. It will not work with JBoss Cache 2.
Tell Hibernate you want to enable caching of entities and collections. No need to set this property if you don't:
hibernate.cache.use_second_level_cache=true
Tell Hibernate you want to enable caching of query results. No need to set this property if you don't:
hibernate.cache.use_query_cache=true
If you have enabled caching of query results, tell Hibernate if you want to suppress costly replication of those results around the cluster. No need to set this property if you want query results replicated:
hibernate.cache.region.jbc2.query.localonly=true
See Chapter 3, Configuration for full details on configuration.