Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

ClassCastException when loading from Redis Cache

$
0
0

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();}

Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>