I believe that by using Hibernate's 2nd level cache wisely will make a good job regarding the performance of my application, and to do that I've started studying it from the internet and a Hibernate course. Although there are pretty good explanations on 2nd level cache and basically of the way it works, my goal is to figure out exactly how things work, starting with specific questions I did not find, hence I will ask a few question on Hibernate's cache in general and on 2nd level cache in particular.
Notes about answering:
A. I would appreciate answering questions even if some seem obvious or irrelevant.
B. If a question depends upon cache provider, I'd like to hear the answer which tells about Ehcache
C. Answering part of the questions due to uncertainty will be welcome
Questions:
Once 2nd level cache is configured, does the 1st level cache get disabled? If not then how the process of events occur when trying to get an entity, which cache level gets hit first?
Does a query cache save a query text as HQL or as native SQL?
Will 2nd level cache work the same using Hibernate through JPA and Hibernate directly?
I understood query cache participates with 2nd level cache by hitting the 2nd level cache with ID's which are located in the query cache. What if some of the ID's, from some reason no longer sit in the 2nd level cache, will all the entities be fetched again, or just the part which doesn't exist?
Regarding synchronization – By updating an entity, which is stored in the 2nd level cache, in a certain transaction – When will the entity be updated in the 2nd level cache if at all? Will appreciate further details of how this act may influence on both 2nd level cache and query cache.
Thank you!