Quote:
You will only hit the cache if you ask for an entity by its id.
This is not completely true. Because beyond
Code:
hibernate.cache.use_second_level_cache=true
you could also activate the second level query cache
Code:
hibernate.cache.use_query_cache=true
Activating the second level query cache allows you to cache also queries (together which its result set)
into 2L-cache.
Furthermore you must tell hibernate explicitely to put the query into 2L cache
mynamedQuery.setCacheable(true);
Also it is important to have the 2L itself enabled and regarding persistent class configured for being cached into 2Lcache.
Otherwise second level query cache is contraproductive.