• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

how to disable hibernate query cache

HI Experts,

I Want to disable query cache in my project.

In Hibernate configuration file i made it as
<prop key="hibernate.cache.use_query_cache">false</prop>

is it enough to disable or in query level i have to set as false

 public List<Object> findByHql(final String hqlQuery) {        
        HibernateCallback<Object> hibernateCallback = new HibernateCallback<Object>() {            
            public List<Object> doInHibernate(Session session) {
                Query hibernateQuery = session.createQuery(hqlQuery);
                return hibernateQuery.setCacheable(true).list(); ///here also i need to set cacheable as false or not
        List<Object> list = (List<Object>) getHibernateTemplate().execute(hibernateCallback);       

Open in new window

can some one suggest me.
how to test query cache is disabled.

1 Solution
Raghu MutalikdesaiSenior Manager in a leading IT Services companyCommented:
It is the other way around. Query caching is disabled by default, assuming you don't have the relevant key in your Hibernate configuration file:

Open in new window

Not having the key in configuration and having the key with value is set to false is one and the same. You need not call the below code explicitly if you have the above mentioned arrangement.

Open in new window

If you look at the Hibernate Documentation on Query Cache, it is apparent that it takes more work to enable query caching than disabling it. You can use simple logging to test query caching. Typically, you would clear the cache before executing the Hibernate query:

Open in new window

Then, execute your query and check the result. You can execute the following code on a specific entity which is part of your result

Open in new window

There are couple of good articles that can give you an insight, specifically on testing part: Understanding Query Cache and How does Query Cache work?
srikoteshAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now