# Problem deserializing bytecode enhanced entity from redisson second level cache

**URL:** <https://discourse.hibernate.org/t/problem-deserializing-bytecode-enhanced-entity-from-redisson-second-level-cache/7859>\
**Category:** Hibernate ORM\
**Created:** [June 21, 2023, 3:37am UTC](https://discourse.hibernate.org/t/problem-deserializing-bytecode-enhanced-entity-from-redisson-second-level-cache/7859 "2023-06-21T03:37:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kai\_Hackemesser](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kai_hackemesser/32/405_2.png) [@Kai\_Hackemesser](https://discourse.hibernate.org/u/Kai_Hackemesser)\
**Post date:** [June 21, 2023, 3:37am UTC](https://discourse.hibernate.org/t/problem-deserializing-bytecode-enhanced-entity-from-redisson-second-level-cache/7859/1 "2023-06-21T03:37:31Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [June 21, 2023, 9:58am UTC](https://discourse.hibernate.org/t/problem-deserializing-bytecode-enhanced-entity-from-redisson-second-level-cache/7859/2 "2023-06-21T09:58:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kai\_Hackemesser](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kai_hackemesser/32/405_2.png) [@Kai\_Hackemesser](https://discourse.hibernate.org/u/Kai_Hackemesser)\
**Post date:** [June 22, 2023, 12:37am UTC](https://discourse.hibernate.org/t/problem-deserializing-bytecode-enhanced-entity-from-redisson-second-level-cache/7859/3 "2023-06-22T00:37:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [June 22, 2023, 8:06am UTC](https://discourse.hibernate.org/t/problem-deserializing-bytecode-enhanced-entity-from-redisson-second-level-cache/7859/4 "2023-06-22T08:06:03Z")

</div>

Please create an issue in the issue tracker([https://hibernate.atlassian.net](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](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java)) that reproduces the issue.

---

<div class="post-metadata">

**Author:** ![Kai\_Hackemesser](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kai_hackemesser/32/405_2.png) [@Kai\_Hackemesser](https://discourse.hibernate.org/u/Kai_Hackemesser)\
**Post date:** [June 22, 2023, 9:24pm UTC](https://discourse.hibernate.org/t/problem-deserializing-bytecode-enhanced-entity-from-redisson-second-level-cache/7859/5 "2023-06-22T21:24:44Z")

</div>

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.
