-->
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: Ehcache and query cache - works or not?
PostPosted: Wed Mar 12, 2008 9:30 am 
Newbie

Joined: Tue Jun 26, 2007 3:08 am
Posts: 10
Hello,
I have a problem with using Query Cache in my program, it puts queries into cache but always misses:
SecondLevelCacheHitCount: 100
QueryCacheHitCount: 0
QueryCacheMissCount: 11
QueryCachePutCount: 11
QueryExecutionCount: 11

My code looks like this:
Code:
part of unit test setup:
AnnotationConfiguration cfg = new AnnotationConfiguration();
factory = cfg.configure("hibernate-test.cfg.xml").buildSessionFactory();

part of test:
   @Test
   public void testGetAllCarMarks() {
      populateCarMarks();
      CarMarkDAO dao = new CarMarkDAO();
      dao.setSessionFactory(factory);
      //without container let us start DAO manually
      try {
         dao.initDao();
      } catch (Exception e) {
         e.printStackTrace();
         fail();
      }
      List<CarMark> carMarks = dao.getAllCarMarks();
      assertNotNull(carMarks);
      assertEquals(10, carMarks.size());
      for(int i = 0; i < 10; i++) {
         dao.getAllCarMarks();
      }
      dao.getStatistics();
   }

hibernate.cfg.xml:
   <session-factory>
      <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
      <property name="connection.url">jdbc:hsqldb:mem:openidserver_db</property>
      <property name="connection.username">sa</property>
      <property name="connection.password"></property>
      <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
      <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
      <property name="cache.provider_configuration_file_resource_path">ehcache-test.xml</property>
      <property name="cache.use_query_cache">true</property>
      <property name="cache.use_second_level_cache">true</property>
      <!--
      <property name="cache.use_structured_entries">true</property>
      -->
      <property name="generate_statistics">true</property>
      <property name="show_sql">true</property>
      <property name="hbm2ddl.auto">create</property>
      <mapping class="test.car.entities.CarMark" />

   </session-factory>

ehcache config:
<ehcache>
    <diskStore path="java.io.tmpdir"/>
    <defaultCache
      maxElementsInMemory="10000"
      eternal="false"
      overflowToDisk="false" />
</ehcache>

DAO code which is tested is based on Spring, I do not launch container but initDAO() with:
public class CarMarkDAO extends HibernateDaoSupport {

   @Override
   protected void initDao() throws Exception {
      super.initDao();
      getHibernateTemplate().setCacheQueries(true);
   }
   
   public List<CarMark> getAllCarMarks() {
      List<CarMark> carMarks = getHibernateTemplate().findByCriteria(DetachedCriteria.forClass(CarMark.class));
      //List<CarMark> carMarks = getHibernateTemplate().find("from CarMark");
      return carMarks;
   }
}


I have also tried this in pure Hibernate also get misses so I think it's some bug with configuration or ... I don't know exactly.
I use hibernate 2.5.0-ga and ehcache 1.2.4 from Maven repositories.

Anybody have similar problem with put / miss on cache query and solved it?

Thx in advance,
Adr


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.