Problem deserializing bytecode enhanced entity from redisson second level cache

Hi,

Since we updated our dependency from redisson-hibernate-53 from 3.18 to any more recent one we have errors with deserialization from the Redis server. Stack traces look like:

java.lang.ClassCastException: class org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1 cannot be cast to class [Ljava.lang.Object; (org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1 is in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @3f985a86; [Ljava.lang.Object; is in module java.base of loader 'bootstrap')
at org.hibernate.type.ComponentType.assemble(ComponentType.java:640)
at org.hibernate.type.CollectionType.assemble(CollectionType.java:302)
at org.hibernate.type.TypeHelper.assemble(TypeHelper.java:101)
at org.hibernate.cache.spi.entry.StandardCacheEntryImpl.assemble(StandardCacheEntryImpl.java:135)
at org.hibernate.loader.entity.CacheEntityLoaderHelper.convertCacheEntryToEntity(CacheEntityLoaderHelper.java:308)
at org.hibernate.loader.entity.CacheEntityLoaderHelper.processCachedEntry(CacheEntityLoaderHelper.java:174)
at org.hibernate.loader.entity.CacheEntityLoaderHelper.loadFromSecondLevelCache(CacheEntityLoaderHelper.java:147)
at org.hibernate.persister.entity.AbstractEntityPersister.initializeEnhancedEntityUsedAsProxy(AbstractEntityPersister.java:4541)
at org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor.forceInitialize(EnhancementAsProxyLazinessInterceptor.java:221)
at org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor.lambda$handleRead$0(EnhancementAsProxyLazinessInterceptor.java:133)
at org.hibernate.bytecode.enhance.spi.interceptor.EnhancementHelper.performWork(EnhancementHelper.java:206)
at org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor.handleRead(EnhancementAsProxyLazinessInterceptor.java:98)
at org.hibernate.bytecode.enhance.spi.interceptor.AbstractInterceptor.readObject(AbstractInterceptor.java:153)
at ourorg.ourapp.jpa.crs.TransactionType.$$_hibernate_read_description(TransactionType.kt)
at ourorg.ourapp.jpa.crs.TransactionType.getDescription(TransactionType.kt:46)
at ourorg.ourapp.api.jobs.mapper.JobEntityToDtoMapper.toDTO(JobEntityToDtoMapper.kt:37)
at ourorg.ourapp.api.jobs.JobController.patch(JobController.kt:234)

Any suggestions?

Did you purge/clear the cache after the update? Maybe the new version uses a different serialization format.

We were spending some time on reproducing the problem this morning. We were clearing the redis cache with a clean build, made the app serve a request, noticed it been written to the cache, requested again and it failed with a stack as above. It is not an artifact of a bytecode mismatch if the same runtime is storing and reading the cache. The only change to make it work is to use Version 3.18.
What we also noticed is that there is another change necessary - the stack above only happens if we open the reflect module - else the stack message looks like:

org.hibernate.cache.CacheException: com.esotericsoftware.kryo.KryoException: java.lang.reflect.InaccessibleObjectException: Unable to make field private transient volatile boolean java.lang.reflect.Executable.hasRealParameterData accessible: module java.base does not “opens java.lang.reflect” to unnamed module @3c46e67a

Please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(hibernate-test-case-templates/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub) that reproduces the issue.

Yesterday I got intel from the Redisson community, the problem is that they swapped out the default codec in V3.19. I am now trying to figure out how to inject the Reddison client that I configure in SpringBoot into the hibernate setup, which is not spring context aware. Looks like I need to create my own factory for this.