开发者

hibernate createSQLQuery use CacheQuery?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜