-->
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: query cache and object references
PostPosted: Thu Oct 28, 2010 9:36 am 
Newbie

Joined: Wed Sep 22, 2010 12:01 pm
Posts: 7
hey,

Some data used by my application are modified by external batchs, so i need to have the possibility to clear my entity/collection cache. I do this using the 2 following methods :

Code:
private void clearCollectionCache(SessionFactory factory) {
      Map<String, CollectionMetadata> roleMap = factory.getAllCollectionMetadata();
      for (String roleName : roleMap.keySet()) {
         factory.getCache().evictCollectionRegion(roleName);
      }
}

private void clearEntityCache(SessionFactory factory) {
   Map<String, ClassMetadata> entityMap = factory.getAllClassMetadata();
   for (String entityName : entityMap.keySet()) {
      factory.getCache().evictEntityRegion(entityName);
   }
}


Everything works fine. However i also need to clear the query cache for 2 reasons :
- i'm not sure of the behavior of the query cache, the object references of the query cache can no longer be coherent
- i do need to execute my HQL/criteria requests because they performs joins which improve my performance

So I tried to clear the query cache. But when i do so, the request is executed the first time and all the objects i need are retrieved, but the second time, the request doesn't appear (it has been put in cache) but my objects are not retrieved (they need to be retrieved from the db :/ generating a lot of loads...).

Why my objects are not put in the second level cache the first time my request has been performed ?

The third time the objects are correctly retrieved from the cache.

Extra question : when a HQL/ criteria request is executed (not in cache) and retrieve object which are in L2 cache, is the L2 cache used ?

Thanks a lot!


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.