-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate uses wrong caching regions
PostPosted: Thu Sep 25, 2008 10:00 am 
Newbie

Joined: Tue Sep 02, 2008 9:53 am
Posts: 6
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 :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 10:16 am 
Newbie

Joined: Tue Sep 02, 2008 9:53 am
Posts: 6
It seems like I found a solution myself. I've added a prefix property to persistence.xml:
Code:
<property name="hibernate.cache.region_prefix" value=""/>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.