I have some experements with second level cache, and as I got for better performance you should configure cache for all child objects of your parent.
That is for the following object model
Code:
Parent -<> ChildA
|-<> ChildB
|-<> ChildC
you should configure read-only/nonstrict-read-write cache for Parent, ChildA, ChildB and ChildC (if you need all your object be in the memory else use read-write cahce)
Code:
<hibernate-mapping>
<class name="full.class.name.Parent" table="`Parent`" batch-size="10"
mutable="false" dynamic-update="false" dynamic-insert="false">
<cache usage="read-only"/>
...
and for cache tuning, configure ehcache regions in the ehcache.xml for each of those classes, be aware of eternal="true" in that example:
Code:
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
/>
<cache name="full.class.name.Parent"
maxElementsInMemory="10000"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
/>
<cache name="full.class.name.ChildB"
maxElementsInMemory="10000"
eternal="true"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
/>
...
</ehcache>
For all collections in your classes enable cache too,
Code:
<bag...>
<cache .../>
</bag>
In addition, use QueryCache:
in ehcache.xml
Code:
<cache name="net.sf.hibernate.cache.QueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="false"
/>
in java code:
Code:
session.createQuery(queryStr).setCacheable(true);
And I think you already read the following docs:
http://www.hibernate.org/158.html
http://ehcache.sourceforge.net/
Also wait for chapter 5 of
http://www.manning.com/catalog/view.php?book=bauer, Christian Bauer said there will be helpfull examples and best practicces
http://forum.hibernate.org/viewtopic.php?t=930848
read the thread
http://forum.hibernate.org/viewtopic.php?t=931007
--
Regards,
Leonid