I am wondering whether it is possible to pre-load specific sets of entities (i.e. static lookup tables) into the L2 cache using generic JPA settings. Is this possible or is it JPA vendor (Hibernate, EclipseLink, etc...) dependant?
I doubt that there's a setting for such a task. However, what seemed to work when I tried exactly that, is a simple JPQL query, which should fetch the objects into the second level cache (at least Hibernate did that):
entityManager.createQuery("select x from Entity x").getResultList();
This is plain JPA and therefore not vendor dependent and could be executed in a constructor of a corresponding DAO (@Repository or @Service in Spring) or in a prefetch thread.
I wouldn't know of any such JPA feature. I'd simply trigger the respective calls (services, repositories, DAOs or whatever they are) during startup of your application.
Given the 2nd-level cache is properly setup and configured the entities representing your static lookup tables will remain in the cache until...well, that depends of course on your caching settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With