?
Solved

how to disable hibernate query cache

Posted on 2016-07-14
2
Medium Priority
?
504 Views
Last Modified: 2016-08-20
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.

Thanks,
0
Comment
Question by:srikotesh
2 Comments
 
LVL 7

Accepted Solution

by:
Raghu Mutalikdesai earned 2000 total points
ID: 41758930
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:
hibernate.cache.use_query_cache

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.
setCacheable(false)

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:
session.getSessionFactory().getCache().evictAllRegions();

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
session.get()

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?
0
 
LVL 2

Author Comment

by:srikotesh
ID: 41763769
THANKS A LOT
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question