|
23 | 23 |
|
24 | 24 | import jakarta.persistence.Convert;
|
25 | 25 | import jakarta.persistence.Converter;
|
26 |
| -import jakarta.persistence.Embedded; |
27 | 26 | import jakarta.persistence.EntityListeners;
|
28 | 27 | import jakarta.persistence.IdClass;
|
29 | 28 | import jakarta.persistence.PostLoad;
|
@@ -200,16 +199,22 @@ private void contributeHibernateHints(RuntimeHints hints, Class<?> managedClass)
|
200 | 199 | return;
|
201 | 200 | }
|
202 | 201 | ReflectionHints reflection = hints.reflection();
|
| 202 | + registerInstantiatorForReflection(reflection, |
| 203 | + AnnotationUtils.findAnnotation(managedClass, embeddableInstantiatorClass)); |
203 | 204 | 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)); |
212 | 209 | });
|
213 | 210 | }
|
| 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 | + } |
214 | 219 | }
|
215 | 220 | }
|
0 commit comments