Reputation: 5
I have a class stored using Spring Data:
@Entity
class CorePlayer(
val uuid: UUID,
var name: String,
var firstJoin: Long,
var lastJoin: Long,
) : BaseEntity()
I am then accessing that class using a JpaRepository with some Redis caching:
@Repository
interface CorePlayerRepository : JpaRepository<CorePlayer, Long> {
@Cacheable("core_player_uuid", key = "#uuid", unless = "#result == null")
fun findByUuid(uuid: UUID): CorePlayer?
@Cacheable("core_player_name", key = "#name", unless = "#result == null")
fun findFirstByName(name: String): CorePlayer?
@Caching(
put = [
CachePut("core_player_name", key = "#result.name"),
CachePut("core_player_uuid", key = "#result.uuid")
]
)
fun save(entity: CorePlayer): CorePlayer
}
When I call this code:
repository.findByUuid(uuid) ?: repository.save(CorePlayer(...))
I get a strange error:
Could not read JSON: Failed to parse type 'uk.m4xy.modules.core.player.CorePlayer' (remaining: ''):
Cannot locate class 'uk.m4xy.modules.core.player.CorePlayer',
problem: uk.m4xy.modules.core.player.CorePlayer
My CacheManager is setup as follows
@Bean
fun cacheManager(connectionFactory: RedisConnectionFactory): CacheManager {
val cacheConfig: RedisCacheConfiguration = RedisCacheConfiguration
.defaultCacheConfig()
.disableCachingNullValues()
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(StringRedisSerializer()))
.serializeValuesWith(
RedisSerializationContext.SerializationPair.fromSerializer(
GenericJackson2JsonRedisSerializer().configure {
it.registerModules(KotlinModule.Builder().build())
})
)
.entryTtl(Duration.ZERO) // Infinite Cache
return RedisCacheManager.builder(connectionFactory)
.cacheDefaults(cacheConfig)
.build()
}
Is this a classpath issue, a jackson-kotlin issue or an oversight. Any advice would be appreciated.
Upvotes: 0
Views: 25