1

in my project i have enabled hibernate query caching (using ehcache) and 2nd level entity caching for some of the entities . also in the documentation it is mentioned that query caching does not store the complete entity object and only stores the entity identity. So we should enable 2nd level entity caching as well in order to achieve better performance.

I was wondering if query caching region and entity caching region should be same ? or is it ok for them to be different and still entity will be returned from 2nd level cache if its a result of query cached in query cache? Another question I have is, is it ok to configure different 2nd level cache regions for different entities based on business categorization ?

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
Mayur
  • 303
  • 1
  • 3
  • 14

1 Answers1

0

The query cache uses its own region, just like entities should use individual regions.

This allows you to configure each region based on the cache access patterns.

It does not matter whether the query cache is in one region while the entities being cached are in different regions. If will work just fine.

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
  • Vlad thank you the reply. You mention that entities should use "individual" regions ? Is it not ok if I specify common region for all entities ? Are there any issues in doing so ? Also I think I tried configuring s different region for query cache and a different region for the entity cache ( name other than hibernate default) and I think for fetching an entity returned by the query it fired an explicit sql to fetch the entity even though the entity was in its second level cache .this is an issue for me however i will try this once more and let you know of the results are same . – Mayur Oct 03 '18 at 01:51
  • Speaking about Infinispan implementation, I would actually recommend having different regions for queries and entities - I am not sure if using the same region is tested at all. The default settings is that there's a default query region and individual region for each entity. The issue you describe is either misconfiguration or bug - I suggest showing some minimal example that demonstrates this. – Radim Vansa Oct 03 '18 at 07:08
  • @RadimVansa i will try to put a sample snippet of how things are configured at my end, for better understanding of situation – Mayur Oct 03 '18 at 07:28