diff --git a/src/main/java/org/springframework/data/convert/ClassGeneratingEntityInstantiator.java b/src/main/java/org/springframework/data/convert/ClassGeneratingEntityInstantiator.java index 025ea6f91..23efffcd6 100644 --- a/src/main/java/org/springframework/data/convert/ClassGeneratingEntityInstantiator.java +++ b/src/main/java/org/springframework/data/convert/ClassGeneratingEntityInstantiator.java @@ -326,7 +326,7 @@ public class ClassGeneratingEntityInstantiator implements EntityInstantiator { Class type = entity.getType(); try { - return ReflectUtils.defineClass(className, bytecode, type.getClassLoader(), type.getProtectionDomain()); + return ReflectUtils.defineClass(className, bytecode, type.getClassLoader(), type.getProtectionDomain(), type); } catch (Exception e) { throw new IllegalStateException(e); } diff --git a/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java b/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java index 9bf2c28ea..133f09983 100644 --- a/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java +++ b/src/main/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactory.java @@ -318,7 +318,7 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert Class type = entity.getType(); try { - return ReflectUtils.defineClass(className, bytecode, type.getClassLoader(), type.getProtectionDomain()); + return ReflectUtils.defineClass(className, bytecode, type.getClassLoader(), type.getProtectionDomain(), type); } catch (Exception e) { throw new IllegalStateException(e); } @@ -1037,8 +1037,9 @@ public class ClassGeneratingPropertyAccessorFactory implements PersistentPropert mv.visitMethodInsn(INVOKEVIRTUAL, JAVA_LANG_INVOKE_METHOD_HANDLE, "invoke", String.format("(%s%s)%s", referenceName(JAVA_LANG_OBJECT), referenceName(JAVA_LANG_OBJECT), getAccessibleTypeReferenceName(entity)), false); - - mv.visitTypeInsn(CHECKCAST, getAccessibleTypeReferenceName(entity)); + if (isAccessible(entity)) { + mv.visitTypeInsn(CHECKCAST, Type.getInternalName(entity.getType())); + } } else { // this. <- for later PUTFIELD