Hibernate Second Level CacheHazelcast® 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 JavaHibernate 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.
First-level CachingHibernate 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.
Second-level CachingTo 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 HibernateHazelcast 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 ArchitectureClient-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 ArchitectureCluster-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-OnlyWith 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
- 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