The query cache is a very simple mechanism that stores the results for a specific key. In the case of your own request, this key will be your request and all parameters.
So, for example, the key could be:
*----------------------------------------------------------------------------------------* | Query Cache | |----------------------------------------------------------------------------------------| | ["select * from table as t where t.id=? and p.column=?", [ 1 , "value"] ] -> [ 2 ] ] | *----------------------------------------------------------------------------------------*
From this point of view, each request can be cached - in certain scenarios. Of course, the request should be handled by Hibernate classes, and not directly through a JDBC connection.
And, BTW, it's easy to find out if your request will use the request cache or not! All this in the log files under org.hibernate.cache .
And there’s a big catch in all this - if you run your own request, it will supplant all entities and entries of the second level cache! At least that was until the last version I used! This way you can use your own queries, but since Hibernate cannot decide what they are doing, it will clear the cache to avoid changes to the data made by this query that are not reflected in the cache objects.
As such, there are many problems with the query cache, and you should consider whether you want to use this feature! Look at this article or this one . I try to avoid using query caches in my work, I use only SLC for objects ...
Łukasz Rżanek
source share