I've been banging my head against wall reagrding this issue for over a month. Please Help..
I want to do second level entity caching (using EHcache) in hibernate for few masters table.i followed http://ehcache.org/documentation/2.7/integrations/hibernate and few other links and did the configuration as follows:
for cfg file
<!-- For Second Level Caching -->
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name = "net.sf.ehcache.configurationResourceName">/ehcache.xml</property>
<!-- For statistics -->
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.cache.use_structured_entries">true</property>
<property name = "net.sf.hibernate.cache.UpdateTimestampsCache ">true</property>
hbm file.
<hibernate-mapping>
<class name="com.example.ehcacheSample.stateMstr" table="STATE_MSTR">
<cache include="all" usage="read-only" region = "stateMstr"/>
...........
</class>
</hibernate-mapping>
ehcache.xml
<cache name = "stateMstr"
maxElementsInMemory="1"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk= "true" />
now regarding that i have certain issue
the document says that for second level caching, entity needs to be loaded using primary key only. which means that for getting a table of 100 rows in the cache we have to run a loop 100 times using the primary key of the columns as the serializable id. In other words if I would like to create a replica of the table in the cache, Is loading an entity row by row an only option ??
secondly if we want to fetch the primary Id of a row using a given value of any column of the same row from the cache ,is that possible without hitting a database query ? For eg if the deptt name is known and i would like to fetch the id of the deptt and deptt table is cached .. is that possible to get the id without hitting a database query.