-->
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.  [ 1 post ] 
Author Message
 Post subject: unable to cache Named query results for more than 2 minutes
PostPosted: Wed Jul 22, 2009 3:46 am 
Newbie

Joined: Tue Jul 21, 2009 5:07 am
Posts: 3
Hi,

I am trying to cache named queries in JPA, to cache the Named Query results for a particular time period of more than 20 minutes.

I have written the ehcache.xml and defined the same reference in the persistence.xml, In the Entity option object, for the Named Query I have defined the Hints --> QueryHint = cacheable to true and the region.

But the query is being cached for only 2 minutes(120seconds). I would like to cache the query about 20 minutes.


Please find the below are the code in persistence.xml, ehcache.xml, POJO(Example: Option.java) and DAO(OptionDAO.java).



POJO(Option.java):

@NamedQuery(name = "findOptionsByLineOfBusinessAndStatus", query = "from Option where uniqueOptionKey.lineOfBusinessId= :lineOfBusiness AND optionStatus= :stateCode", hints = { @QueryHint(name = "org.hibernate.cacheable", value = "true"), @QueryHint(name = "org.hibernate.cacheRegion", value = "query.AdministrativeAreasPerCountry") })



persistence.xml:

<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.cache.provider_configuration_file_resource_path" value="ehcache.xml"/> <!-- ehcache.xml is along with the persistence.xml in META-INF-->


ehcache.xml

<ehcache>
<diskStore path="c:\\web\\"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="360000"
timeToLiveSeconds="360000"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="360000"
memoryStoreEvictionPolicy="LRU"
/>

<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="360000"
timeToLiveSeconds="360000"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="360000"
memoryStoreEvictionPolicy="LRU"
/>

<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="360000"
timeToLiveSeconds="360000"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="360000"
memoryStoreEvictionPolicy="LRU"
/>

<cache name="query.AdministrativeAreasPerCountry"
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="180000"
timeToLiveSeconds="864000"
overflowToDisk="true"/>
</ehcache>



OptionDAO:

Query query = getEntityManager().createNamedQuery("from Option where uniqueOptionKey.lineOfBusinessId= :lineOfBusiness AND optionStatus= :stateCode)";
query.setParameter(LINE_OF_BUSINESS, lineOfBusiness);
query.setParameter(STATE_CODE, stateCode);

options = (List<Option>) query.getResultList();


Could you please provide some information on the same. where exactly is missing the configuration properties being set are overridden to the default. The query being cached for 2 minutes is the default time to cache.


Thanks and Regards,
Jayadev S


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

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.