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.
hibernate.cache.provider_classOSCache and Hibernate 3.2 integrate though OSCacheProvider.
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.
Cache Region ConfigurationTo 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 HibernateTo 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> |