This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Query Level Cache Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Query Level Cache" Watch "Query Level Cache" New topic

Query Level Cache

lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
I understand difference between 1st level and 2nd level cache.
Wanted to understand How is query level cache different from 1st and 2nd Level Cache

as per my understanding if i run a query with ? ie
from employee emp where

then only it can be cached in a 2nd Level cache … so query like
from employee emp where

will not be cached .. to cache these a query cache is used , right ?

BUT in my code if i have queries as below ... do we see one DB hit or Two DB hit
from employee emp where

from employee e where
// extra spaces in query string + e used instead of emp
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

The following Link may guide you precisely
Hibernate Cache Strategies

All The Best

Thanks & Regards
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

Hi lavnish,

Second level cache stores the object in a map, having primary key as Map's key and Object as map value. Second level cache is used only while accessing the object by primary key ie by using session.get(), session.load().

Query cache store the query result in map, having query and its parameters as Map's key and result as map value. Query cache can be used to cache & reuse the result of any query irrespective of primary key usage in it.

Salil Verma
I agree. Here's the link:
subject: Query Level Cache
It's not a secret anymore!