Info

This page is intended to give integration support for Hibernate 2.1 and for pre OSCache 2.4 releases.
It's recommended to use the new Hibernate 3.2 classes.

Hibernate is a powerful, ultra-high performance object/relational persistence and query service for Java. Hibernate lets you develop persistent objects following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework. Extremely fine-grained, richly typed object models are possible.

Hibernate 2.1 features support for plugin cache providers and is designed to integrate with distributed caches (2.1 also implements more aggressive use of the cache). net.sf.hibernate.cache.CacheProvider is the extension point for user-defined cache integration.

Hibernate 2.1.1 or higher is required.

hibernate.cache.provider_class

OSCache and Hibernate 2.1 integrate though OSCacheProvider.

Warning

Unfortunately, at this time the OSCacheProvider distributed with Hibernate 2.1.x is not suited to clustering with OSCache. A patch has been submitted to the Hibernate team but not yet applied. Even if you do not require clustering, we recommend use of these patched versions of OSCacheProvider and OSCache for Hibernate 2.x and OSCacheProvider and OSCache for Hibernate 3.x. Just cut-n-paste the code and use the provider class you create as the hibernate.cache.provider_class as shown below.

To enable OSCache in Hibernate's configuration, add the following line to hibernate.cfg.xml:

hibernate.cfg.xml
<property name="hibernate.cache.provider_class">my.patched.provider.package.OSCacheProvider</property>

The default refresh period is CacheEntry.INDEFINITE_EXPIRY. The first time a cacheable query is done, the cache has no effect on speed. On the second and successive queries, the cache will be populated and available to be hit.

Object Identifiers

Object identifiers must have well-behaved toString() methods, because OSCache uses the toString() method for the key of the cache. Therefore it needs to create a unique identifier for the object being stored.

Cache Region Configuration

To modify the refresh period, CRON expression, add the region configuration to your oscache.properties file, as demonstrated below:

[region].refresh.period = 4000
[region].cron = * * 31 Feb *

# The maximum cache capacity can only be set per region if you use the 
# net.sf.hibernate.cache.OSCacheProvider distributed with Hibernate.
[region].capacity = 5000

# The patched version distributed with OSCache only allows a single cache.capacity setting and saves memory.

The com.mypackage.domain.Customer is Hibernate's internal cache region, which defaults to the classname, and which can be altered by setting Hibernate's configuration property hibernate.cache.region_prefix .

Source Code