Quote:
The Entity cache is not seperate from the query cache?
It depends how you configure/define your cache regions and the 2L-Cache itself.
By default they are stored in separate cache regions.
Quote:
The ids cached for a query can only be cached if the Entity itself is cached?
No, if fear you did'nt really understand what i meant. I try to explain it by example.
user-query1: select * from A
result-set query1 :
id = 1 name ="a"
id = 2 name ="b"
id = 3 name ="c"
id = 4 name ="d"
query result-set is cached now as something like following
{123123453,1,2,3,4} // the first entry is a timestamp, the others are primary key values
new transaction on a new session
user-query2: select * from A
query results cached !
if now the 4 instances are not cached anymore in the entity-region,
then hibernate will issue 4 separate queries in order to build up the result-set with entities
select * from A where id=1;
select * from A where id=2;
select * from A where id=3;
select * from A where id=4;
As you can see, it is feasible to cache a query into 2L-cache while not caching the entities of the concerning table,
but it is not recommended as instead to avoid 1 database hit you produce 4 database hits.