I only want to cache some static read only tables like list of countries and every time this table gets hits the data should be read from the cache.
Paul Sturrock wrote:A cached query is a different thing from cached entities. Remember, queries do not necessarily load entities (i.e. select property1 from entity will just get that property). When you cache a query what you cache are the ids of entities that match the criteria when the query was run.
My understanding on your point is like
A query wil hit the database every time it got fired but if the query is cacheble the DB hit is saved for the second and subsequent times .
the query cache makes the query cachable but the secong level cache makes the Entities catchable based on their identifier(pk)
The second level cache is only used when accessing the object by Primary Key, means the searching for whole entities based on Primary Key
ie with session.get(), session.load()
Please correct me if i am wrong.