Source

oscache / docs / wiki / Hibernate 2.1 and pre OSCache 2.4 support.html

Full commit
<html>
    <head>
        <title>OSCache - 
        Hibernate 2.1 and pre OSCache 2.4 support
         </title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>

    <body>
	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
		    <tr>
			    <td valign="top" class="pagebody">
				    <table cellpadding='5' width='85%' cellspacing='8px' class='noteMacro' border="0" align='center'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="./icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b class="strong">Info</b><br />
<p>This page is intended to give integration support for Hibernate 2.1 and for pre OSCache 2.4 releases.<br/>
It's recommended to use the new <a href="Hibernate.html" title="Hibernate">Hibernate 3.2</a> classes.</p></td></tr></table>

<p><a href="http://www.hibernate.org/" title="Visit page outside Confluence">Hibernate</a> 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.</p>

<p>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). <b>net.sf.hibernate.cache.CacheProvider</b> is the extension point for user-defined cache integration.</p>

<p><a href="http://www.hibernate.org/6.html" title="Visit page outside Confluence">Hibernate 2.1.1</a> or higher is required.</p>

<h3><a name="Hibernate2.1andpreOSCache2.4support-hibernate.cache.providerclass"></a>hibernate.cache.provider_class</h3>

<p>OSCache and Hibernate 2.1 integrate though OSCacheProvider. </p>

<table cellpadding='5' width='85%' cellspacing='8px' class='warningMacro' border="0" align='center'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="./icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b class="strong">Warning</b><br />
<p>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 <a href="Hibernate 2.1 Cache Provider.html" title="Hibernate 2.1 Cache Provider">OSCacheProvider</a> and <a href="Hibernate 2.1 Cache Adapter.html" title="Hibernate 2.1 Cache Adapter">OSCache</a> for Hibernate 2.x and <a href="Hibernate 3 Cache Provider.html" title="Hibernate 3 Cache Provider">OSCacheProvider</a> and <a href="Hibernate 3 Cache Adaptor.html" title="Hibernate 3 Cache Adaptor">OSCache</a> 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.</p></td></tr></table>

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

<div class="code"><div class="codeHeader"><b>hibernate.cfg.xml</b></div><div class="codeContent">
<pre class="code-xml"><span class="code-tag">&lt;property name=<span class="code-quote">"hibernate.cache.provider_class"</span>&gt;</span>my.patched.provider.package.OSCacheProvider<span class="code-tag">&lt;/property&gt;</span></pre>
</div></div>

<p>The default refresh period is <a href="http://www.opensymphony.com/oscache/api/com/opensymphony/oscache/base/CacheEntry.html#INDEFINITE_EXPIRY" title="Visit page outside Confluence">CacheEntry.INDEFINITE_EXPIRY</a>. 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.</p>

<table cellpadding='5' width='85%' cellspacing='8px' class='noteMacro' border="0" align='center'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="./icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b class="strong">Object Identifiers</b><br />
<p>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.</p></td></tr></table>

<h3><a name="Hibernate2.1andpreOSCache2.4support-CacheRegionConfiguration"></a>Cache Region Configuration</h3>

<p>To modify the refresh period, CRON expression, add the region configuration to your <a href="Configuration.html" title="Configuration">oscache.properties</a> file, as demonstrated below:</p>

<div class="preformatted"><div class="preformattedContent">
<pre>[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.
</pre>
</div></div>

<p>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 <a href="http://www.hibernate.org/hib_docs/reference/en/html/session-configuration.html" title="Visit page outside Confluence">hibernate.cache.region_prefix</a> .</p>

<h3><a name="Hibernate2.1andpreOSCache2.4support-SourceCode"></a>Source Code</h3>

<ul><li><a href="Hibernate 2.1 Cache Adapter.html" title="Hibernate 2.1 Cache Adapter">Hibernate 2.1 Cache Adapter</a></li><li><a href="Hibernate 2.1 Cache Provider.html" title="Hibernate 2.1 Cache Provider">Hibernate 2.1 Cache Provider</a></li><li><a href="Hibernate 3 Cache Adaptor.html" title="Hibernate 3 Cache Adaptor">Hibernate 3 Cache Adaptor</a></li><li><a href="Hibernate 3 Cache Provider.html" title="Hibernate 3 Cache Provider">Hibernate 3 Cache Provider</a></li></ul>

                    			    </td>
		    </tr>
	    </table>
    </body>
</html>