Solved

how to disable hibernate query cache

Posted on 2016-07-14
2
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2

Author Comment

by:srikotesh
ID: 41763769
THANKS A LOT
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches users how to migrate an existing Wordpress website to a new domain.
This video teaches viewers about errors in exception handling.

690 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