OSCache - Hibernate

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 3.2 features support for plugin cache providers and is designed to integrate with distributed caches (3.2 also implements more aggressive use of the cache). net.sf.hibernate.cache.CacheProvider is the extension point for user-defined cache integration. Hibernate Core 3.2.3 GA or higher is required.
| Warning Unfortunately, at this time the OSCacheProvider distributed with Hibernate 3.2 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 OSCacheProvider and OSCache for Hibernate 3.2 delivered by OSCache 2.4 and higher. The OSCache only allows a single cache.capacity setting and saves memory.
### hibernate.cache.provider_class OSCache and Hibernate 3.2 integrate though OSCacheProvider.
| Clustering The clustered cache invalidation only works for entity updates when usage="nonstrict-read-write".
To enable OSCache for Hibernate's second level cache add the following line to Hibernate's configuration e.g. hibernate.cfg.xml: hibernate.cfg.xml
    <property name="hibernate.cache.provider_class">com.opensymphony.oscache.hibernate.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 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 . ### Configure a different configuration file for Hibernate To configure a different configuration file use the following parameter in the Hibernate's configuration: hibernate.cfg.xml
    <property name="com.opensymphony.oscache.configurationResourceName">path to oscache-hibernate.properties</property>