Solved

how to disable hibernate query cache

Posted on 2016-07-14
2
66 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 500 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 1

Author Comment

by:srikotesh
ID: 41763769
THANKS A LOT
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now