Announcement Announcement Module
Collapse
No announcement yet.
Caching queries with HibernateTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Caching queries with HibernateTemplate

    Hi

    I am currently working on a project with Spring and Hibernate.
    In one part i have to do a lot of lookups in the database.
    If i do this with :
    HibernateTemplate hibernateTemplate = getHibernateTemplate();
    hibernateTemplate.setCacheQueries(true);
    hibernateTemplate.setQueryCacheRegion("query.XX");
    hibernateTemplate().findByNamedParam("select XXX").list()

    Then the perfomance is very poor, it seems it dosent use the 2 lvl cache at all, wich as far as i understand also is in accordance with the documentation for find().
    I have tried with the HibernateCallback method, and this performs poorly aswell !!! Even tough you here have the option of creating the query directly on the hibernate session, it still seems to go directly to the database without using the cache.

    If i use hibernate directly like this :
    session.createQuery(
    "from XXX");
    query.setString("fork", stationsfork);
    query.setCacheable(true);
    query.setCacheRegion("query.XXX");
    return query.list();
    then the performance is much better (by a factor 8) since now it uses the cache.

    My question is then, how do i use HibernateTemplate together with a query cache ???

    I use Hibernate 2.1.6, Spring 1.1.5 and Ehcache 1.1.

    Regards
    Timm
Working...
X