I’ve set up ehcache on our Java application, which uses Spring and Hibernate.
However, when I run Junit tests and print the stats, it seems there is nothing in cache:
OUTPUT OF CACHE MANAGER STATS ON EVERY CACHE:
COM.****.SERVICES.CLARITY.DOMAIN.ACTIONITEM.BYRESOURCEUNIQUENAME:
getCacheHits: 0
getCacheMisses: 0
getObjectCount: 0
COM.****.SERVICES.CLARITY.DOMAIN.ACTIONITEM:
getCacheHits: 0
getCacheMisses: 0
getObjectCount: 0
COM.****.SERVICES.CLARITY.DOMAIN.RESOURCE:
getCacheHits: 0
getCacheMisses: 0
getObjectCount: 0
CONTENT OF THE MAPPING FILE (ONLY PARTS, TOO BIG TO PASTE ALL):
<class name="ActionItem" table="CAL_ACTION_ITEMS" mutable="false" lazy="false" >
<cache region="com.****.services.clarity.domain.ActionItem" usage="read-only" include="all" />
[…]
<query name="byResourceUniqueName" cacheable="true" cache-region="com.****.services.clarity.domain.ActionItem.byResourceUniqueName" read-only="true">
FROM ActionItem WHERE id IN (
SELECT DISTINCT actionItemId FROM ActionItemAssignee as aia WHERE assigneeId IN (
SELECT userId FROM Resource WHERE uniqueName = :uniqueName
)
)
ORDER BY dueDate
</query>
CONTENT OF EHCACHE.XML:
<cache
name="com.****.services.clarity.domain.ActionItem"
maxElementsInMemory="2000" eternal="false" timeToIdleSeconds="0"
timeToLiveSeconds="600" overflowToDisk="false" />
<cache
name="com.****.services.clarity.domain.ActionItem.byResourceUniqueName"
maxElementsInMemory="2000" eternal="false" timeToIdleSeconds="0"
timeToLiveSeconds="60" overflowToDisk="false" />
<defaultCache maxElementsInMemory="200" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
memoryStoreEvictionPolicy="LRU" />
HIBERNATE CONFIG:
<property name="hibernateProperties">
<value>
hibernate.format_sql=true
hibernate.dialect=org.hibernate.dialect.OracleDialect
hibernate.cache.provider_class=net.sf.ehcache.hibernate.EhCacheProvider
hibernate.cache.use_query_cache=true
hibernate.show_sql=true
</value>
</property>
</bean>
Any ideas on how to populate the cache ?
Thanks.
Normally the items get populated to the cache by Hibernate automatically.
One thing I noticed in your configuration is that you didn’t enable the statistics. Add the property
to your session factory’s configuration and see, if numbers occur in your output.