I geta ClassCastException when reading a response from Redis Cache. Everything looks good when hitting the DB and store it in Redis Cache. The second read out of the Redis Cache terminates in a ClassCastException when i want to iterate over the linked HashSet. When I debug the Hashmap all values are correct, until I reach the foreach loop. When I want to evaluate an Entry I get the Exception.Is it a configuration property that i missed in the Cacheconfig?
Code:
Jpa Repository
@EntityGraph(value = "Usr.fullCascade")@Cacheable(value = "UsrEntity", cacheManager = "userEntity")Set<UsrEntity> findByCompanyidAndStatusNot(int cid, UserRoleStatus status);
Service
Set<UsrEntity> usrEntity = userRepository.findByCompanyidAndStatusNot(companyID,UserRoleStatus.X);usrEntity.forEach(user -> { userDtos.add(companyUserDataMapper.toDto(user));});
CacheConfig
@BeanJedisConnectionFactory jedisConnectionFactory() { RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6379); return new JedisConnectionFactory(redisStandaloneConfiguration);}@Beanpublic RedisTemplate redisTemplate() { RedisTemplate template = new RedisTemplate<>(); template.setConnectionFactory(jedisConnectionFactory()); return template;}@Bean("userEntity")public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() .entryTtl( Duration.ofHours(1)); redisCacheConfiguration.disableCachingNullValues(); return RedisCacheManager .builder( redisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory)) .cacheDefaults(redisCacheConfiguration).build();}