Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Caching in Hibernate: Query Cache

Query Cache: 

 When executes the query the retrieved objects would not been stored in session's cache.Query Cache is responsible for caching the results of the query. Query cache can not enable by default.

Why Query cache is disabled by default?
If we executes a large query retrieving n number of objects and store those objects in cache, those objects should occupy the entire cache space.Then there is no point to maintain the cache.That's the reason Query cache disabled by default.

In Hibernate Configuration file set the property of query cache true, then the query cache can be enabled in the entire application
                <property name="hibernate.cache.use_query_cache">true</ property>

then set the cacheable true in the session's query , all objects retrieving through this query are stored in     query cache.
              Query query=session.createQuery("from Project p,Allocation a where p.pid==a.pid");
                             query.setCacheable(true);





NOTE: Query Cache does not store the state of the objects, it caches only the identifiers and results of Value Types.The Query cache can be used to optimize the applications, however there are pitfalls also in.


                                                                                                                  Vissu


This post first appeared on Java Spring Hibernate, please read the originial post: here

Share the post

Caching in Hibernate: Query Cache

×

Subscribe to Java Spring Hibernate

Get updates delivered right to your inbox!

Thank you for your subscription

×