I am using Spring Redis data to cache sequential JPA objects in Redis using org.springframework.data.redis.cache.RedisCacheManager
Here is a way:
@Override @Cacheable(value = MapCacheConfiguration.DATABASE_CACHE_NAME, key = "#root.method.name") public Curriculum findCurriculumByMemberId(Long memberId) { return curriculumRepository.findCurriculumByMemberId(memberId); }
Unfortunately, after rebooting my boot application, the objects are still cached in Redis, and I get org.hibernate.LazyInitializationException
This may be due to the reason described in this message , i.e. access to an isolated object using hibernate - in my case, a serialized object left in the cache.
Can anyone advise a strategy to solve this problem?
- Do I have to clear / delete the cache when destroying my application, given that the process of re-filling the cache is expensive and the application will be located in the cloud (Heroku), where dinosaurs / containers will be destroyed and recreated (and therefore restarted) quite often.
- Or is there a way to connect to cached objects in entity manager?
- Is there a better solution?
spring-cache spring-data-jpa spring-data-redis hibernate jpa
balteo
source share