This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How many records are saved in Hibernate cache?

 
Ranch Hand
Posts: 232
2
  • 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.
 
Sheriff
Posts: 24594
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: 232
2
  • 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: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone please help me with this
 
Bartender
Posts: 20924
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • 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.
 
Arun Singh Raaj
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I read in tutorials that the caching works only for session methods ie get(), load() plus HQL queries which do find by IDs.

I want to know that queries that retrieve all records from db like "select * from employee", the results of such queries are not cached?
If it can be cached then how?

Thanks.
 
Tim Holloway
Bartender
Posts: 20924
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the real question is why are you obsessing about stuff like this when you're using legacy Hibernate?

Hibernate JPA is more likely to provide advanced services.
 
Arun Singh Raaj
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do developers not use Second-level cache of hibernate?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!