Project Background: Architecture upgrade, upgrading from Spring 5 to 6.1.5 and Hibernate from 5.3 to 6.2.25, non-Maven project
Issue: After the upgrade, there are casting errors occurring during requests, with the following error message:
class org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1 cannot be cast to class java.lang.String (org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1 is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @5b068087; java.lang.String is in module java.base of loader ‘bootstrap’)
Analysis Process: It should be caused by changes in the Hibernate bytecode enhancer, or changes in the initialization of large fields and proxy modes,
I have read the official migration guide:
considering our project’s bytecode enhancement approach as well,
this enhancement approach had no issues in version 5.3, but problems occurred after the upgrade. Is it possible that this bytecode enhancement approach is no longer compatible? This is based on the findings from the migration guide,‘hibernate.enhancer.enableLazyInitialization’,‘hibernate.enhancer.enableDirtyTracking’,both values have been set to true by default and have been deprecated. Can we remove the enhancement approach used in our project? After removal, will the lazy properties’ fields still be able to be proxied and read normally, or are there new enhancement approaches available? If there are, please provide the new bytecode enhancement API that can be adapted to our project.Thanks!