Q: How do I integrate Coherence and Hibernate?

There are two methods for integrating Coherence and Hibernate: Coherence can be used as an L2 cache provider for Hibernate and Hibernate can be used as a CacheStore provider for Coherence.

Using Coherence as a Hibernate L2 cache provider enables multiple JVMs running the same Hibernate application to share an L2 cache.  The use of Coherence caching in this case is controlled by Hibernate; thus a good understanding of Hibernate L2 caching is required to successfully use this provider. This may be a good fit for applications that:

  - prefer to use Hibernate APIs for data access/management
  - have large/complex object models
  - have complicated transactional requirements
  - have a large cluster of application servers running Hibernate that access the same database

Hibernate can also be used as a CacheStore implementation for Coherence.  Applications that use this approach typically have the following characteristics:

 - prefer to use Coherence APIs for data access/management
 - have simpler object models appropriate for the out-of-the-box Hibernate CacheStore implementation (note that applications with more complex object models can leverage custom CacheStore implementations)
 - have simpler transactional requirements
 - require high performance through the use of Coherence APIs, such as write-behind and aggregations

This example illustrates both integration approaches. See the included readme.txt for further instructions.

References
----------
Hibernate L2 caching: http://www.hibernate.org/hib_docs/v3/reference/en/html/performance.html#performance-cache
CacheStore:           http://wiki.tangosol.com/display/COH33UG/Read-Through%2C+Write-Through%2C+Refresh-Ahead+and+Write-Behind+Caching
