• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How many records are saved in Hibernate cache?  RSS feed

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does the pagination work? If there are 1 million employee records in the database, if you want to see all of them then all the records are fetched in one go or a limited number of records are fetched once?
When the records are displayed as page numbers on your page as 1|2|3|4|5. you click on page number 2, does it hit the database or retrieves from the cache? How many records out of a million can be cached?


Thanks.
 
Marshal
Posts: 24467
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Arun Singh Raaj wrote:If there are 1 million employee records in the database, if you want to see all of them...



Trust me. Nobody wants to be shown a list of 1 million employees with only the scroll-down option to review them. This is a non-problem.
 
Arun Singh Raaj
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay thanks. Please help me with other doubts.
When the records are displayed as page numbers on your page as 1|2|3|4|5. you click on page number 2, does it hit the database or retrieves from the cache? How many records out of a million can be cached?
 
Arun Singh Raaj
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone please help me with this
 
Bartender
Posts: 20728
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caching is a complex topic. In addition to caching done by Hibernate, it's also possible to plug in a cache manager to a Hibernate app. And/or use an external cache system as an intermediary to the database. It entirely depends on how you configure Hibernate and (if used) its backing caches. Sophisticated systems can even be designed to cache different types of records/queries to different degrees.

When you detach an object from Hibernate, Hibernate is obligated to have each and every data record from that query (including all eager-fetches) realized in RAM for the benefit of the application. That's not cache, though, that's the actual records themselves. When retrieving data while still attached, you can consider Hibernate to be doing 'just-in-time' reads from the database, although in actuality there can be caching or pre-fetching, depending on the JDBC driver an Hibernate settings.

Caching is a performance enhancer. As far as I know, Hibernate by default caches nothing by default in order to save system resources and to ensure the timeliness of the data it returns. You would enable caching to enhance queries that are done often so that Hibernate could avoid re-querying the database. And note that caching must be done judiciously or the data in the database might be changed outside the scope of the database, rendering the Hibernate cache useless. Databases do not notify Hibernate when this happens.

I worked on a system that was obligated to return large quantities of data for user review. It takes a very brave person to go past the first 10 pages or so. Far better to have a searchable data set and limit the pages to the important stuff.

Speaking of limiting, many DBMS's have some sort of LIMIT clause in their SQL that can be used to return a slice of results rather than overwhelm the system with tons of data. I think that that's what we did on my system (it has been many years now). For people who do insist on reading dozens of pages, this means re-issuing the query multiple times and you should be aware that if the data is being changed while all this is going on, results can be somewhat unpredictable. Materialized Views can help in that case.

So, in other words, our advice is A) try not to pull massive quantities of data in the first place. B) try reading the Hibernate manual.
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!