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: ehcache not hits, only puts
PostPosted: Wed Jan 06, 2010 5:55 am 
Newbie

Joined: Fri Dec 26, 2008 1:13 am
Posts: 8
Hi,

I am trying to get the ehcache to work in my app, but somehow it never hits the cache, but instead it keeps on sending the same query to the MySQL database. Probably I am misunderstanding something. This is how I fetch rows from the table:

Code:
Client client = (Client) _session.createSQLQuery("SELECT * FROM client WHERE name = :name")
            .addEntity(Client.class)
            .setString("name", credsDTO.clientName)
            .setCacheable(true)
            .setMaxResults(1)
            .uniqueResult();


The Client class has a read-only cache configured. When I investigate the statistics for the respective cache I can see that rows are correctly added to the cache, but they are never being used when the same query is executed again!

This is how I get the stats:

Code:
Statistics stats = HibernateSessionFactory.getInstance().getStatistics();
SecondLevelCacheStatistics cacheStats = stats.getSecondLevelCacheStatistics(Client.class.getCanonicalName());
System.out.println("Hit count1:  " + stats.getSecondLevelCacheHitCount());
System.out.println("Miss count1: " + stats.getSecondLevelCacheMissCount());
System.out.println("Put count1:    " + stats.getSecondLevelCachePutCount());
System.out.println("Hit count2:  " + cacheStats.getHitCount());
System.out.println("Miss count2: " + cacheStats.getMissCount());
System.out.println("Put count2:    " + cacheStats.getPutCount());
System.out.println("Entries:    " + cacheStats.getEntries().toString());
      
for (int i=0; i<stats.getSecondLevelCacheRegionNames().length; ++i) {
    System.out.println("Region:   " + stats.getSecondLevelCacheRegionNames()[i]);
}


And this is the output:

Code:
Hit count1:  0
Miss count1: 0
Put count1:    5
Hit count2:  0
Miss count2: 0
Put count2:    5
Entries:    {1={users=1, _version=null, fullName=XXX, _lazyPropertiesUnfetched=true, name=XXX, _subclass=mysql.contentional.generated.Client}, 4={users=4, _version=null, fullName=YYY, _lazyPropertiesUnfetched=true, name=YYY, _subclass=mysql.contentional.generated.Client}}
Region:   org.hibernate.cache.StandardQueryCache
Region:   org.hibernate.cache.UpdateTimestampsCache
Region:   mysql.contentional.generated.Client


So why do I keep seeing the same query being sent to MySQL and the hit counts are always on 0, even though exactly the same query is executed over and over again?

I think I tries all options and all combinations, so I guess I am misunderstanding something. Anyway, here are the options I am using:

Code:
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.cache.use_structured_entries">true</property>


Thank you,
Andrej


Top
 Profile  
 
 Post subject: Re: ehcache not hits, only puts
PostPosted: Wed Jan 06, 2010 10:27 am 
Newbie

Joined: Fri Dec 26, 2008 1:13 am
Posts: 8
I found the following entries in the log:

Quote:
http-8080-1 - DEBUG - JDBCTransaction - (JDBCTransaction.java:147) - committed JDBC Connection
http-8080-1 - DEBUG - ConnectionManager - (ConnectionManager.java:427) - aggressively releasing JDBC connection
http-8080-1 - DEBUG - ConnectionManager - (ConnectionManager.java:464) - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
http-8080-1 - DEBUG - SessionFactoryImpl - (SessionFactoryImpl.java:868) - evicting second-level cache: mysql.contentional.generated.Client


Somehow the cache is cleared after a session is closed!

I am using Tomcat6 and BlazeDS.

How can I prevent it doing so?

Thank you,
Andrej


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.