File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes regarding QueryCache Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "regarding QueryCache" Watch "regarding QueryCache" New topic
Author

regarding QueryCache

Raj chiru
Ranch Hand

Joined: Aug 12, 2008
Posts: 141
Hi....Friends,

I'm new to hibernate,could Anybody explain to me what is org.hibernate.cache.QueryCache.?Is this query cache is second cache or Is this relate to session-factory?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


    JavaRanch FAQ HowToAskQuestionsOnJavaRanch
    Raj chiru
    Ranch Hand

    Joined: Aug 12, 2008
    Posts: 141
    Hi Paul,
    Thanks for your reply.

    one more doubt, Is second-level-cache is associates with session-Factory object[/i]?
    Paul Sturrock
    Bartender

    Joined: Apr 14, 2004
    Posts: 10336

    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.
    Raj chiru
    Ranch Hand

    Joined: Aug 12, 2008
    Posts: 141
    Hi....
    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?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: regarding QueryCache