pb00067 wrote:
answer to question 1:
It will go to the database, even if objects with ids 1,2,3 are already in cache.
There exists only one scenario, where this query don't will hit the database:
a) you enabled also the second-level-query-cache
b) you already did execute the same query (from Something where id in (1,2,3)) with specifying
query.setCacheable(true) before executing it.
c) After the first execution of the query (=the one which did hit the database and fill the second-level-query-cache) the table Something were not object to any modification. This because any insert/delete/update action in the involved table makes hibernate consider obsolete the cached query result set.
d) the second-level-query-cache is not expired.
e) the actual query is executed again with query.setCacheable(true)
If all this conditions are true, then the query should'nt hit the database.
answer to question 2:
The same thing as with question 1 with the difference that in this case 2 tables are involved,
so any change in something or children table will convert obsolete your cached result-set.
Thank you very much. It looks like if I don't enable query cache the second level cache is pretty much useless. In what scenario (if query cache is off) second level is used?
And one more thing. As I already wrote I get objects from data base by their ids. But every time those ids are different. In one query I may have
1,2,3 in another 2,1,3. The same objects, but different queries. So, probability I have exactly the same query is very low. It means query cache is not useful.
Any ideas how can I improve performance in such case?
Thank you,
Andrey