Access Keys:
Skip to content (Access Key - 0)

GemFire Versions

About GemFire Enterprise 6.5

Getting Started

Documentation

Resources

Articles

Developer Notes

Tools & Libraries

Toggle Sidebar

Hibernate Cache Module

The VMware vFabricTM GemFire® Hibernate Cache Module provides fast, scalable, distributed L2 caching for JBoss Hibernate. After performing a minimal number of configuration changes, GemFire will cache Hibernate data. Depending on your usage model, you can replicate data across multiple peers, partition data across multiple servers, or manage your data in many other customizable ways.

For information about GemFire purchase options as they relate to your desired Hibernate configuration, refer to Hibernate Cache and GemFire Purchase Options.

This page contains the following content:

Why Use GemFire?

  • General
    • GemFire's L2 cache solution improves Hibernate performance
    • Reduces traffic to your database server
    • Simple to configure: requires just a few changes to hibernate.cfg.xml
    • Flexible caching options, supporting several local and distributed configurations
    • Access to many of the GemFire Enterprise features
  • Performance
    • Mesh-like architecture provides single hop access to any entity
    • Designed to minimize serialization costs
  • Scalability
    • Data can be partitioned across the entire cluster
    • Smart heap utilization / smart eviction algorithm
    • Supports all Hibernate concurrency strategies (read only, read/write, non-strict read/write, transactional)
    • Ensures data consistency without expensive distributed locks
    • Overflow to disk on each cache node (i.e. shared nothing persistence)
    • Supports tiered caching

Installing GemFire and the Module

  1. If you have not already done so, download and install JBoss Hibernate.
  2. You also need to download and install GemFire Enterprise, as described at Setting Up GemFire. You must ensure that GemFire is part of the classpath when you run Hibernate. Alternatively, you can place the gemfire.jar in a location that is accessible to your application.
  3. If you do not already have the GemFire module, download an evaluation copy of Hibernate Cache Module 1.0 from the SpringSource download center.
  4. Unpack the module and ensure that the included GemFire module jar ("gemfire.modules-1.0.jar") is accessible to your application.
The GemFire evaluation license allows you to create up to three GemFire processes. In order to use GemFire with additional processes, refer to the section on GemFire Licenses in the System Administrator's Guide.

Setting Up the Module

Edit Hibernate's hibernate.cfg.xml file in order to use the GemFire module.

  1. Turn on L2 Cache
    In the hibernate.cfg.xml file, turn on the L2 cache:
    Turning on L2 cache with hibernate.cfg.xml
      <property name="hibernate.cache.use_second_level_cache">true</property>
    
  2. Set Region Factory or Cache Provider
    Associate the region factory class with GemFireRegionFactory:
    Setting region factory with hibernate.cfg.xml (version 3.3+)
      <property name="hibernate.cache.region.factory_class">
        com.gemstone.gemfire.modules.hibernate.GemFireRegionFactory
      </property> 
    

  3. Determine Cache Usage Mode
    You must determine the cache usage mode for the entities in each region. There are four types of usage modes:
    Mode Description
    Read Only This mode is used when you do not plan on modifying the data already stored in your persistent storage.
    Read/Write This mode is used when you plan to both read from and write to your data.
    Non-strict Read/Write This mode is a special read/write mode that has faster write performance; however, only use this mode if no more than one client will update content at a time.
    Transactional This mode allows for transaction-based data access.
  4. Set Cache Usage Mode
    The usage mode can either be set using the hibernate-mapping file or through Java annotations.
    1. To set the mode with the hibernate-mapping file, refer to this example:
      Cache usage via entity_name.hbm.xml
          <hibernate-mapping package="PACKAGE">
            <class name="ENTITY_NAME" ...>
              <cache usage="read-write|nonstrict-read-write|read-only"/>
              ...
            </class>
          </hibernate-mapping>
        

      In this example, PACKAGE is the name of the entity package and ENTITY_NAME is the name of your entity. The cache usage values are described in "Determine Cache Usage Mode"). Refer to the Hibernate documentation for further information.

    2. To set the mode using annotations, your class definition should look something like this:
      Cache usage via Java annotations
      import org.hibernate.annotations.Cache; 
      import org.hibernate.annotations.CacheConcurrencyStrategy;
           
      @Entity @Cacheable
      @Cache(region = 'REGION_NAME', 
      usage = CacheConcurrencyStrategy.READ_ONLY|READ_WRITE|NONSTRICT_READ_WRITE|TRANSACTIONAL)
      public class MyClass implements Serializable {
        ...
      }
      

      In this example, REGION_NAME is the region name and MyClass is the name of your class. The CacheConcurrencyStrategy values are described in "Determine Cache Usage Mode"). Refer to the Hibernate documentation for further information.

  5. Start JBoss Hibernate
    You are now ready to build, deploy, and run your Hibernate application, which will also launch GemFire. See the JBoss Hibernate documentation for further information about performing these actions.
  6. Verify that GemFire Started Successfully
    Similar to Hibernate, GemFire uses Simple Logging Facade for Java (SLF4J) to log messages. Upon successful startup, GemFire will log the following message:
    Verifying GemFire started
    2010-11-15 INFO [com.gemstone.gemfire.modules.hibernate.GemFireRegionFactory] - <Initializing GemFire Modules Version 1.1>

    SLF4J can send this and other GemFire log messages to several logging frameworks. Refer to the SLF4J website for additional information.

Further Configuration

By default, once you've set up Hibernate to work with the GemFire module, GemFire will run automatically with pre-configured settings. Specifically:

  • GemFire runs in a peer-to-peer configuration, rather than a client/server configuration.
  • GemFire processes are discovered using a default multicast channel.
  • GemFire "locators", which provide discovery and load balancing services, are not used for member discovery.
  • The cache region is replicated.

These settings might not reflect your preferred usage. To change these and other settings, refer to the following page:

Release Notes

top

Child Pages

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
Adaptavist Theme Builder (3.4.0-M2-conf210) Powered by Atlassian Confluence 2.10.3, the Enterprise Wiki.