@@ -188,39 +188,56 @@ private void contributeCallbackHints(RuntimeHints hints, Class<?> managedClass)
188
188
189
189
@ SuppressWarnings ("unchecked" )
190
190
private void contributeHibernateHints (RuntimeHints hints , @ Nullable ClassLoader classLoader , Class <?> managedClass ) {
191
- Class <? extends Annotation > embeddableInstantiatorClass = loadEmbeddableInstantiatorClass (classLoader );
192
- if (embeddableInstantiatorClass == null ) {
193
- return ;
194
- }
195
191
ReflectionHints reflection = hints .reflection ();
196
- registerInstantiatorForReflection (reflection ,
197
- AnnotationUtils .findAnnotation (managedClass , embeddableInstantiatorClass ));
198
- ReflectionUtils .doWithFields (managedClass , field -> {
199
- registerInstantiatorForReflection (reflection ,
200
- AnnotationUtils .findAnnotation (field , embeddableInstantiatorClass ));
201
- registerInstantiatorForReflection (reflection ,
202
- AnnotationUtils .findAnnotation (field .getType (), embeddableInstantiatorClass ));
203
- });
204
- }
205
192
206
- @ SuppressWarnings ("NullAway" )
207
- private void registerInstantiatorForReflection (ReflectionHints reflection , @ Nullable Annotation annotation ) {
208
- if (annotation == null ) {
209
- return ;
193
+ Class <? extends Annotation > embeddableInstantiatorClass = loadClass ("org.hibernate.annotations.EmbeddableInstantiator" , classLoader );
194
+ if (embeddableInstantiatorClass != null ) {
195
+ registerForReflection (reflection ,
196
+ AnnotationUtils .findAnnotation (managedClass , embeddableInstantiatorClass ), "value" );
197
+ ReflectionUtils .doWithFields (managedClass , field -> {
198
+ registerForReflection (reflection ,
199
+ AnnotationUtils .findAnnotation (field , embeddableInstantiatorClass ), "value" );
200
+ registerForReflection (reflection ,
201
+ AnnotationUtils .findAnnotation (field .getType (), embeddableInstantiatorClass ), "value" );
202
+ });
203
+ ReflectionUtils .doWithMethods (managedClass , method -> registerForReflection (reflection ,
204
+ AnnotationUtils .findAnnotation (method , embeddableInstantiatorClass ), "value" ));
205
+ }
206
+
207
+ Class <? extends Annotation > valueGenerationTypeClass = loadClass ("org.hibernate.annotations.ValueGenerationType" , classLoader );
208
+ if (valueGenerationTypeClass != null ) {
209
+ ReflectionUtils .doWithFields (managedClass , field -> registerForReflection (reflection ,
210
+ AnnotationUtils .findAnnotation (field , valueGenerationTypeClass ), "generatedBy" ));
211
+ ReflectionUtils .doWithMethods (managedClass , method -> registerForReflection (reflection ,
212
+ AnnotationUtils .findAnnotation (method , valueGenerationTypeClass ), "generatedBy" ));
213
+ }
214
+
215
+ Class <? extends Annotation > idGeneratorTypeClass = loadClass ("org.hibernate.annotations.IdGeneratorType" , classLoader );
216
+ if (idGeneratorTypeClass != null ) {
217
+ ReflectionUtils .doWithFields (managedClass , field -> registerForReflection (reflection ,
218
+ AnnotationUtils .findAnnotation (field , idGeneratorTypeClass ), "value" ));
219
+ ReflectionUtils .doWithMethods (managedClass , method -> registerForReflection (reflection ,
220
+ AnnotationUtils .findAnnotation (method , idGeneratorTypeClass ), "value" ));
210
221
}
211
- Class <?> embeddableInstantiatorClass = (Class <?>) AnnotationUtils .getAnnotationAttributes (annotation ).get ("value" );
212
- reflection .registerType (embeddableInstantiatorClass , MemberCategory .INVOKE_DECLARED_CONSTRUCTORS );
213
222
}
214
223
215
224
@ Nullable
216
- private static Class <? extends Annotation > loadEmbeddableInstantiatorClass ( @ Nullable ClassLoader classLoader ) {
225
+ private static Class <? extends Annotation > loadClass ( String className , @ Nullable ClassLoader classLoader ) {
217
226
try {
218
- return (Class <? extends Annotation >) ClassUtils .forName (
219
- "org.hibernate.annotations.EmbeddableInstantiator" , classLoader );
227
+ return (Class <? extends Annotation >) ClassUtils .forName (className , classLoader );
220
228
}
221
229
catch (ClassNotFoundException ex ) {
222
230
return null ;
223
231
}
224
232
}
233
+
234
+ @ SuppressWarnings ("NullAway" )
235
+ private void registerForReflection (ReflectionHints reflection , @ Nullable Annotation annotation , String attribute ) {
236
+ if (annotation == null ) {
237
+ return ;
238
+ }
239
+ Class <?> embeddableInstantiatorClass = (Class <?>) AnnotationUtils .getAnnotationAttributes (annotation ).get (attribute );
240
+ reflection .registerType (embeddableInstantiatorClass , MemberCategory .INVOKE_DECLARED_CONSTRUCTORS );
241
+ }
225
242
}
226
243
}
0 commit comments