• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

Configure Hibernate Cache

This section provides a complete guide on configuring Hibernate applications with NCache.

Note

This feature is also available in the NCache Community Edition.

Prerequisites to Configure Hibernate Cache

Before configuring Hibernate cache ensure that the following prerequisites are fulfilled:

  • For using NCache Hibernate Maven packages for NCache Community Edition, replace the ncache-hibernate with ncache-community-hibernate in your pom.xml file.
  • Make sure to include the following maven dependencies in your pom.xml file.
<dependency>
    <groupId>com.alachisoft.ncache</groupId>
    <artifactId>ncache-hibernate</artifactId>
    <version>x.x.x</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>x.x.x</version>
</dependency>

Hibernate Cache Configuration

NCache has to be configured in the application's Hibernate configuration file as a second level cache. Following is a sample hibernate configuration file hibernate.cfg.xml with Hibernate cache configuration.

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.cache.use_second_level_cache">true</property>
    <property name="hibernate.cache.region.factory_class">com.alachisoft.ncache.NCacheRegionFactory</property>
    <property name="ncache.application_id">myapp</property>
    <property name="hibernate.cache.use_query_cache">true</property>
  </session-factory>
</hibernate-configuration>

Properties added in the Hibernate’s configuration files are explained as under:

  • Enable the use of a second level cache in your application by adding the following property in the Hibernate configuration section's session-factory tag:
<property name="hibernate.cache.use_second_level_cache">true</property>
  • Configure NCache as Hibernate's second level cache provider. For Hibernate 3.6+, add the following property in Hibernate's configuration file under the session-factory tag:
<property name="hibernate.cache.region.factory_class">com.alachisoft.ncache.NCacheRegionFactory</property>

hibernate.cache.region.factory_class: This option lets you specify NCache's region cache factory class for Hibernate 3.6+. Hibernate will use this cache factory class to initialize and use NCache as a second level cache.

hibernate.cache.provider_class: This option lets you specify NCache as a second level cache provider. You need to mention NCache's cache provider class for Hibernate cache. This is how it knows how to call second-level cache.

  • NCache provider for Hibernate identifies each application by an application-id that is later used to find the appropriate configuration for that application from the NCache configuration file for Hibernate ncache-hibernate.xml. This application-id must be specified in Hibernate's configuration file. Add the following property in Hibernate's configuration session-factory tag for this purpose:
<property name="ncache.application_id">myapp</property>
  • To use NCache as a query cache, enable the query cache by adding the following property:
<property name="hibernate.cache.use_query_cache">true</property>

See Also

Initialize Cache
Hibernate First Level Cache
Configure Cacheable Objects and Regions
Use Query Caching

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Community
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top