title: Second level cache vs query cache vs collection cache?
body: <p>As per my understanding, Second level cache will be used when the objects are loaded using their primary key. This includes fetching of associations.I can think of only above session.get(), session.load methods where second level cache will come in to picture.</p>
  
  <p>If association is collection or some other entity , how it can be cached ? For example :- </p>
  
  <pre><code>  @Cacheable
    public class Department{
     private List Employees;
     private DepatmentDetail detail ;
  
  }
  </code></pre>
  
  <p>How can i make association Employees and detail cacheable ? I think i need to mention @cache above associations Employees and detail. <strong>But that didn't work?</strong></p>
  
  <p>when developer does department.getEmployees(), hibernate will internally fire the query  i.e</p>
  
  <pre><code> select * from employees where deptId =1;
  </code></pre>
  
  <p>Now if i use query cache where i explicitly make above query and fetch the results, query will be fired again to db. why query is fired again . I think this is related to how hibernate internally stores the result of second level cache and query cache(they may be stored in separate regions). If somebody can throw light on this aspect also, it will be great.</p>