I'm using EHCache with Hibernate. The caching works, but entities are cached in wrong regions.
For example I've added "@Cache(usage=CacheConcurrencyStrategy.READ_WRITE, region="tickets")" to the entity "Ticket". But if I use EHCache's statistics to look at the cache I see many the elements cached in a region named "ticketing-ear_ear,ticketing-ejb_jar,ticketing.tickets" which uses the default region's settings. The region "tickets" also exists, but it stays empty.
I also added the caching region to most queries using "query.setHint("org.hibernate.cacheable", true).setHint("org.hibernate.cacheRegion", "tickets")" but it's the same problem there.
The settings I used to add the caching in the persistence.xml file:
Code:
<property name="cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<property name="cache.use_query_cache" value="true"/>
<property name="cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
Parts of my ehcache.xml:
Code:
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
<cache name="tickets"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="60"
timeToLiveSeconds="60"
overflowToDisk="false"
/>
I'm also using EHCache in some EJBs and it uses the right regions there.
How can I fix this? Do I have to define some kind of naming prefix? It's great to finally have caching in Hibernate working, but it would be even better if it would use the right settings :)