Win a copy of Terraform in Action this week in the Cloud 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

hibernate cache

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In hibernate caching, If I execute a query ,that result set will be stored in Cache,
Later ,it is used if the same query is executed

1)If I have a table with 50 Records and I used select statement to select all records in the table, after the query executed, if result set is cached by Hibernate, then I add some data into the table, again I execute the same query, how the hibernate will handle this scenario, whether it will execute query fresh and cache the result ? or some other best way???
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate only uses a query cache if you configure it to do so, and if you do you also need to provide a second level cache. The query cache does not store the state of your results it stores a result set of identifiers, the state is held in the second level cache. Using the query cache and the second level cache are not things you would normally do, the query cache in particular would be one of the last mechanisms you would probably look to to improve performance.


1)If I have a table with 50 Records and I used select statement to select all records in the table, after the query executed, if result set is cached by Hibernate, then I add some data into the table, again I execute the same query, how the hibernate will handle this scenario, whether it will execute query fresh and cache the result ? or some other best way???


Hibernate will go to the cache until it is flushed. If you udate data outside of Hibernate there is no way it can know about this update, such are the dangers of using any caching mechanism with a database. you need to choose carefully when to use one.
 
sanjey asok
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If you udate data outside of Hibernate there is no way it can know about this update




if it is updated using Hibernate ,please explain such scenario
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because Hibernate is managing the sate it can manage the cache, so there is no issue if Hibernate is the only mechanism that updates your data. In the real world however this is not normal behaviour, databases are shared so multiple client can update the data in multiple ways. Hence thinking long and hard about what aspects of caching you might use and whether it is appropriate is key.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic