As I understand it, the second level cache will be used when objects are loaded using their primary key. This includes a selection of associations. I can only think of the methods session.get (), session.load, where the second level cache will be displayed.
If an association is a collection or some other entity, how can it be cached? For example: -
@Cacheable public class Department{ private List Employees; private DepatmentDetail detail ; }
How can I link employees and drill down on caching? I think I need to mention @cache above employee associations and details. But that didn't work?
when the developer does department.getEmployees (), hibernate will internally run the ie request
select * from employees where deptId =1;
Now, if I use a cache request, in which I explicitly make the request above and get the results, the request will be run again on db. why the request is run again. I think this is due to the way hibernate internally saves the result of the second level cache and request cache (they can be stored in separate regions). If someone can shed light on this aspect, it will be great.
java hibernate second-level-cache
M sach
source share