caching - jpa hibernate and 2nd level cache -
my configuration follows
persitence.xml
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.singletonehcacheprovider"/> <property name="hibernate.ejb.classcache.demo.entities.userid" value="read-only"/> <property name="javax.persistence.sharedcache.mode" value="all"/>
ehcache.xml
<?xml version="1.0" encoding="utf-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="http://ehcache.org/ehcache.xsd" updatecheck="false"> <diskstore path="java.io.tmpdir/customer-portlet-cache"/> <defaultcache eternal="false" maxelementsinmemory="1000" overflowtodisk="false" diskpersistent="false" timetoidleseconds="0" timetoliveseconds="600" memorystoreevictionpolicy="lru"/> <cache name="usercache" eternal="true" maxelementsinmemory="999" overflowtodisk="true" diskpersistent="true" timetoidleseconds="0" timetoliveseconds="300" memorystoreevictionpolicy="lru"/> </ehcache>
i have seam component annotated @create gets listing userid , stores them away cache. idea here application warm cache, when access entities application start getting lazy initialization exceptions allover (because entity not associated persistencecontext , has onetomany , manytomany relations , not load entity , if set fetchtype eager more nasty areas)
is there way or workaround getting warm cache when users accesses applications.
don't manually access 2nd level cache. if need separate caching layer, make new one, different hibernate's.
in case, can hibernate.initialize(..)
entities , collections before putting/sending them anywhere
and finally, don't think 2nd level cache configured properly. newer version should this:
<property name="hibernate.cache.use_second_level_cache" value="true" /> <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.singletonehcacheregionfactory" />
Comments
Post a Comment