Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding QueryCache

 
Raj chiru
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    Raj chiru
    Ranch Hand
    Posts: 142
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Paul,
    Thanks for your reply.

    one more doubt, Is second-level-cache is associates with session-Factory object[/i]?
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Eclipse IDE Hibernate Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 142
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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?
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic