-->
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.  [ 7 posts ] 
Author Message
 Post subject: Query cache miss fetch data from DB without 2nd-L cache
PostPosted: Mon Sep 25, 2006 1:42 pm 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
Problem
I need some kind of confirmation for my current understanding/debugging info: in case a query is missing from the query cache, than the data is retrieved using the following algo:
- hit the DB and have a ResultSet
- try to figure out if the entities are present on the Session cache
- if not found in the Session cache than fetch the whole entity from the ResultSet (ignoring so the 2nd level cache - where the entity is available).

Is this correct? If yes, can you give me some details why the 2nd level cache is ignored?

If the above is not correct, please let me know what other information should I provide so that we can figure out why I see the above behavior.

Many thanks in advance,

./alex
--
:Architect of InfoQ.com:
.w( the_mindstorm )p.
Co-founder of InfoQ.com

Other details:

Hibernate version:
3.1.3

Code between sessionFactory.openSession() and session.close():
Code:
return session.createCriteria(CategoryDef.class)
                    .add(Expression.eq("alias", alias))
                    .setCacheable(true)
                     .setCacheRegion("com.c4.infoq.model.Category.QueryCacheFindByAlias");


Name and version of the database you are using:
MySQL 5.0.16

I have enabled 2nd level caching, query caching (using EHCache) and provided some custom ehcache.xml configuration.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 2:06 pm 
Newbie

Joined: Tue Sep 27, 2005 5:44 pm
Posts: 13
Did you include

Code:
<cache usage="read-write" />


in your hbm files you want in the 2nd lvl cache?

_________________
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 2:38 pm 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
I have all (or almost all) the setup correct and working correctly.

After some more investigation, I have the following supposion: there is a query somewhere in the code that is declared as cacheable and uses a regionName that is not present in the ehcache.xml.

At this moment, a new region is created using the settings for the defaultCache, and this is the reason why I see it hitting the DB directly, without trying a 2nd level cache.

Is this the behavior of a query cache with a specified regionName that is not present in the ehcache.xml?

./alex
--
.w( the_mindstorm )p.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 2:50 pm 
Newbie

Joined: Tue Sep 27, 2005 5:44 pm
Posts: 13
well, yes, if the query is not specifically stated in ehcache.xml, then it will look for a definition of StandardQueryCache, ex

Code:
<cache
    name="net.sf.hibernate.cache.StandardQueryCache"
    maxElementsInMemory="250"
    eternal="false"
    timeToLiveSeconds="120"
    overflowToDisk="true">
</cache>


If that's not present, I do not believe it will use the definition for defaultCache as that is for undefined objects, not queries (as far as i know).

Remember, it will only use a cached query if the parameters are identical. Also don't forget to include:
Code:
<!-- Underlying Cache impl. Tracks timestamps of most recent updates to tables -->
<cache
    name="net.sf.hibernate.cache.UpdateTimestampsCache"
    maxElementsInMemory="5000"
    eternal="false"
    overflowToDisk="true">
</cache>


Quote:
- if not found in the Session cache than fetch the whole entity from the ResultSet (ignoring so the 2nd level cache - where the entity is available).

If not found, it will look in the 2nd level cache, provided everything is defined correctly.

Other than that, I'd suggest posting your hbm, cfg, ehcache files for futher help.

_________________
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 3:11 pm 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
cfellows wrote:
well, yes, if the query is not specifically stated in ehcache.xml, then it will look for a definition of StandardQueryCache, ex
[...]


That's exactly what I am trying to point (if I am not completely wrong): if the query region is not specified in the ehcache.xml, than the defaultCache settings will be used, and not the StandardQueryCache.

I guess this is pretty logical: the StandardQueryCache is somehow a normal cache that is used when no region is specified.

Quote:
Other than that, I'd suggest posting your hbm, cfg, ehcache files for futher help.


I really don't think they will help with something. I have plenty of hbm files, and the ehcache file will not lead to any conclusions, as my question is refering to the way the cache regions are behaving and not to their configuration.

./alex
--
.w( the_mindstorm )p.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 3:47 pm 
Newbie

Joined: Tue Sep 27, 2005 5:44 pm
Posts: 13
okay misunderstood you.

alexandrupopescu:

Quote:
- if not found in the Session cache than fetch the whole entity from the ResultSet (ignoring so the 2nd level cache - where the entity is available).

...If the above is not correct, please let me know what other information should I provide so that we can figure out why I see the above behavior.


No, that's not correct. After checking Session, should check 2nd level cache rather than build a new object from scratch using resultset.

To figure out why it is not using your 2nd level cache, might as well post relevant portions of cfg, CategoryDef.hbm.xml, ehcache.xml, and log out put with showsql and DEBUG.

_________________
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 5:07 pm 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
cfellows, thanks for trying to help me out, but I would really appreciate if you would read the whole thread :-).

I have completely changed the initial post, after digging a bit more. The current question is:

when a regionname for a query cache is not found, than a new one is created using the defaultCache settings (and not the org.hibernate.cache.StandardQueryCache).

./alex
--
.w( the_mindstorm )p.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.