0
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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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>

1 Comment

already added that. it work only for DetachedCriteria , but for manual sql like above will it work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.