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:
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:
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.