The query cache is not the second level cache, it is a distinct cache to store the reqults of queries. Hibernate includes three caches:
The first level cache (i.e. the Session)
The second level cache
The query cache
You use the first level cache all the time, the other two are optional. You use the second level cache to store data retrieved from the database as it is loaded in to the session if you configure your mapped classes to do this. The query cache doesn't store data in the same way, it maintains a cache of identifiers that represent result sets from queries and these identifiers are used to access the underlying entitites. Because of this it makes no sense to use the query cache without the second level cache.
Something worth noting: using the second level cache is relatively unusual. Most database backed applications can't tolerate data being held in a cache for a long time. The query cache is therefore even less frequently used. If you have performance problems with querying in Hibernate the query cache is probably the last thing you would look to implement to try to improve things.
I'm not strictly sure I understand your question. The SessionCaftory is a factory that provides Sessions. Sessions are used to access data. This data may come from the database or may be read out of the second level cache if you are using one.
Joined: Aug 12, 2008
My Question is First-level-cache(i.e session) is associates session object,Right?same like that Is second-level-cache is associates with session-Factory object?