Solved

how to disable hibernate query cache

Posted on 2016-07-14
2
216 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding multiple JVM environments to RedHat 6 7 81
maximize the sum of fractions 33 74
Delete .class files at every compile 4 57
Is there a Google Voice API? 9 70
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Suggested Courses

734 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