Forums Register Login

hibernate cache

+Pie Number of slices to send: Send
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???
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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.
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1663 times.
Similar Threads
Retrieve huge result set from DB in chunks
Paging-Query based
Clarifications on session attribute
Resultset with million rows
Is there a default cache?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:11:11.