• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does Hibernate implement caching?

 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am wondering exactly how Hibernate caches data for you. For example if you get a result set for a screen and display that to the user and then the user comes back to that screen a few clicks later, does Hibernate go back to the DB to get the data?

Thanks for any input,
Jehan
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might do. Hibernate has two cache levels: first and second. First is the implicit cache, which is data associated with the current session. Access the same data in the context of the current session and Hibernate will not go back to the database. Second is an optional cache, Hibernate itself doesn't implement this, it provides hooks to integrate a third party cache (such as EHCache). In this instance cache behaviour is defined declaratively.
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer Paul.

So when it comes to the first level caching somewhere Hibernate keeps track of the data it retrieved. So that it can know that it is being asked for the same result set a second time and it does not need to to the DB right?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic