views:

152

answers:

2
Query query=getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(
                "select...

getHibernateTemplate().setCacheQueries(true);
List result= query.list();
getHibernateTemplate().setCacheQueries(false);

return result;

may i know when i do manual "createSQLQuery" how to use cacheQuery? the above doesnt cache the result. show_sql still showing every request get from database

+1  A: 

Try to configure ApplicationContext

<prop key="hibernate.cache.provider_class">org.hibernate .cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
Artic
already added that. it work only for DetachedCriteria , but for manual sql like above will it work?
cometta
Need to investigate.
Artic
A: 

AFAIK when using createSQLQuery, you must use an explicit .addScalar or .addEntity if setCacheable is true, or hibernate gets confused on casting. Apart from that, my understanding is that it should work.

Pascal Thivent