Reputation: 8428
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?
Upvotes: 3
Views: 2052
Reputation: 23535
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.
Upvotes: 1
Reputation: 7868
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.
Upvotes: 2