开发者

hibernate createSQLQuery use CacheQuery?

开发者 https://www.devze.com 2022-12-23 10:59 出处:网络
Query query=getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery( \"select...
Query query=getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(
                "select...

getHibernateTemplate().setCacheQueries(true);
List result= query.list();
getHibernateTemplate().setCacheQueries(f开发者_JAVA百科alse);

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


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.


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消