wood burning stoves 2.0*
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Query Level Cache" Watch "Query Level Cache" New topic
Author

Query Level Cache

lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
Hi
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 emp.id=?

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

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 emp.id=123


from employee e where e.id=123
// extra spaces in query string + e used instead of emp


lavnish.blogspot.com
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
Gopakumar
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 253

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.



Regards
Salil Verma
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Query Level Cache
 
Similar Threads
Caching Technique in Hibernate
Relation between Hibernate Query Cache and Second Level Cache
how to retrieve data from a cache in hibernate
Hibernate problem
Exception while firing the join queries