Ehcache 2.10.8 | Related Documentation | Integrations | Using Ehcache with Hibernate | About Using Ehcache with Hibernate
 
About Using Ehcache with Hibernate
Accelerating Hibernate applications typically involves reducing their reliance on the database when fetching data. Terracotta offers powerful in-memory solutions for maximizing the performance of Hibernate applications:
*Ehcache as a plug-in second-level cache for Hibernate – Automatically cache common queries in memory to substantially lower latency.
*BigMemory for an in-memory store – Leverage off-heap physical memory to keep more of the data set close to your application and out of reach of Java garbage collection.
*Automatic Resource Control for intelligent caching – Pin the hot set in memory for high-speed access and employ fine-grained sizing controls to avoid OutOfMemory errors.
Ehcache easily integrates with the Hibernate Object/Relational persistence and query service. Gavin King, the maintainer of Hibernate, is also a committer to the BigMemory Go's Ehcache project. This ensures Ehcache will remain a first-class data store for Hibernate.
Configuring Ehcache for Hibernate is simple. The basic steps are as follows:
*Download and install Ehcache in your project as described in Downloading and Installing Ehcache for Hibernate.
*Configure Ehcache as a cache provider in your project's Hibernate configuration as described in Configuring Ehcache as the Second-Level Cache Provider.
*Enable second-level caching in your project's Hibernate configuration as described in Enabling Second-Level Cache and Query Cache Settings.
*Configure Hibernate caching for each entity, collection, or query that you want to cache as described in Configuring Hibernate Entities to use Second-Level Caching.
*Configure the ehcache.xml file for each entity, collection, or query configured for caching as described in Configuring ehcache.xml Settings.
For additional information about cache configuration in Hibernate, see the Hibernate product documentation at http://www.hibernate.org/.
Important Notices - PLEASE READ
In order for Hibernate 4.x to work with Ehcache 2.7.5 or higher, you need to install a patch. The problem and the indicated solution are described on the Hibernate website at https://hibernate.atlassian.net/browse/HHH-8732.
Note: The patch is a CODE PATCH that you need to apply to the Hibernate 4 source. Afterwards you need to re-build the Hibernate artifacts.
Installing the patch involves the following steps:
1. Access the patch at https://github.com/hibernate/hibernate-orm/pull/643.patch.
2. Get the Hibernate 4.x source code, for example at https://github.com/hibernate/hibernate-orm/tree/4.3.
3. Patch the Hibernate source code with the patch.
4. Build the Hibernate artifacts. This is explained on the github source page referenced above.
5. Reference the custom-built Hibernate artifacts in your project.
Users of Ehcache for Hibernate prior to Ehcache 2.0 should read Upgrading from Ehcache Versions Prior to 2.0. These instructions are for Hibernate 3.

Copyright © 2010-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release