Hibernate Second Level Cache
Hazelcast® smoothly integrates with Hibernate 3 and Hibernate 4, providing distributed caching support based on Hazelcast IMap technology. Features like scalability, in-memory backups, and automatic eviction are fundamentals of the Hazelcast architecture. Hazelcast brings those features to the Hibernate world.
Hibernate and Java
Hibernate is a well known and commonly used Object-Relational Mapping (ORM) library for the Java language. As a fully compliant JPA (Java Persistence API) persistence provider, Hibernate integrates seamlessly into both Java Enterprise Edition application servers and pure Java Standard Edition applications.
Hibernate lets you easily and quickly access relational data by providing mapping mechanisms from relational database tables, rows, columns and foreign keys to your annotated Java classes. Hibernate generates your SQL queries with an easy-to-use syntax that queries data based on the Java object-oriented domain model.
Hibernate ships with a first-level cache associated with the Session object that principally reduces the number of SQL queries within a given transaction. For example, multiple changes will only result in a single update statement. Hibernate first-level accesses the database for every single query. That can be slow and unpredictable depending on the database load and size.
To provide faster access times and lower access latencies, Hibernate second level cache offers the ability to plug in a second-level cache which keeps pre-provisioned object data in-memory. This cache associates with the Session Factory object. This means that the cache is not restricted to a single session, but is shared across sessions, so data is available to the entire application, not just to the current user. This can greatly improve application performance as commonly used data can be held in-memory in the application tier.
Implied by the name, Hibernate will go to the first level cache first, and if the entity is not there, it will go to the second level.
Using Hazelcast Hibernate
Hazelcast provides multiple ways for you to use Hibernate, depending on your deployment strategies, security aspects, or usage patterns. You can use Hazelcast as a client-server or a cluster-only architecture.
Client-Server architectures are used for high security environments where:
- Different clients might have diverging sets of security policies
- Multiple applications will access the same cache pool
- The environment is deployed on frontend and backend server clusters, such as Tomcat and JBoss
Cluster-only architectures are commonly used with embedded caches. These caches are kept in the memory of the application cluster for the highest possible access speed.
Client/Server and Cluster-Only
With both client-server and cluster-only, Hazelcast offers:
- Scalability to scale the Hibernate second-level cache size up and down
- Transparent integration with backend relational databases using the Hibernate caching API
- Management of the cluster through your web browser with Hazelcast Management Center
Hazelcast also provides you with:
- Distributed computing capabilities across the cluster
- Continuous queries for complex event processing
- Pub/sub, a high-speed topic message system for transmitting messages inside the cluster or between clients and servers
Products in this Use Case: