Skip to content

Commit 183c2f8

Browse files
committed
Refine @EmbeddableInstantiator reflection hints
Based on @odrotbohm proposal to manage a wider set of use cases. Closes gh-31534
1 parent 8eebb5e commit 183c2f8

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessor.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import jakarta.persistence.Convert;
2525
import jakarta.persistence.Converter;
26-
import jakarta.persistence.Embedded;
2726
import jakarta.persistence.EntityListeners;
2827
import jakarta.persistence.IdClass;
2928
import jakarta.persistence.PostLoad;
@@ -200,16 +199,22 @@ private void contributeHibernateHints(RuntimeHints hints, Class<?> managedClass)
200199
return;
201200
}
202201
ReflectionHints reflection = hints.reflection();
202+
registerInstantiatorForReflection(reflection,
203+
AnnotationUtils.findAnnotation(managedClass, embeddableInstantiatorClass));
203204
ReflectionUtils.doWithFields(managedClass, field -> {
204-
Embedded embeddedAnnotation = AnnotationUtils.findAnnotation(field, Embedded.class);
205-
if (embeddedAnnotation != null && field.getAnnotatedType().getType() instanceof Class<?> embeddedClass) {
206-
Annotation embeddableInstantiatorAnnotation = AnnotationUtils.findAnnotation(embeddedClass, embeddableInstantiatorClass);
207-
if (embeddableInstantiatorAnnotation != null) {
208-
Class<?> embeddableInstantiatorClass = (Class<?>) AnnotationUtils.getAnnotationAttributes(embeddableInstantiatorAnnotation).get("value");
209-
reflection.registerType(embeddableInstantiatorClass, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
210-
}
211-
}
205+
registerInstantiatorForReflection(reflection,
206+
AnnotationUtils.findAnnotation(field, embeddableInstantiatorClass));
207+
registerInstantiatorForReflection(reflection,
208+
AnnotationUtils.findAnnotation(field.getType(), embeddableInstantiatorClass));
212209
});
213210
}
211+
212+
private void registerInstantiatorForReflection(ReflectionHints reflection, @Nullable Annotation annotation) {
213+
if (annotation == null) {
214+
return;
215+
}
216+
Class<?> embeddableInstantiatorClass = (Class<?>) AnnotationUtils.getAnnotationAttributes(annotation).get("value");
217+
reflection.registerType(embeddableInstantiatorClass, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
218+
}
214219
}
215220
}

0 commit comments

Comments
 (0)