@@ -357,23 +357,42 @@ protected Optional<E> addPersistentEntity(TypeInformation<?> typeInformation) {
357
357
read .unlock ();
358
358
}
359
359
360
- Class <?> type = typeInformation .getType ();
361
- E entity = null ;
360
+ E entity ;
362
361
363
362
try {
364
363
365
364
write .lock ();
365
+ entity = doAddPersistentEntity (typeInformation );
366
366
367
- entity = createPersistentEntity (typeInformation );
367
+ } catch (BeansException e ) {
368
+ throw new MappingException (e .getMessage (), e );
369
+ } finally {
370
+ write .unlock ();
371
+ }
372
+
373
+ // Inform listeners
374
+ if (applicationEventPublisher != null ) {
375
+ applicationEventPublisher .publishEvent (new MappingContextEvent <>(this , entity ));
376
+ }
377
+
378
+ return Optional .of (entity );
379
+ }
380
+
381
+ private E doAddPersistentEntity (TypeInformation <?> typeInformation ) {
368
382
383
+ try {
384
+
385
+ Class <?> type = typeInformation .getType ();
386
+
387
+ E entity = createPersistentEntity (typeInformation );
369
388
entity .setEvaluationContextProvider (evaluationContextProvider );
370
389
371
390
// Eagerly cache the entity as we might have to find it during recursive lookups.
372
391
persistentEntities .put (typeInformation , Optional .of (entity ));
373
392
374
393
PropertyDescriptor [] pds = BeanUtils .getPropertyDescriptors (type );
375
394
376
- final Map <String , PropertyDescriptor > descriptors = new HashMap <>();
395
+ Map <String , PropertyDescriptor > descriptors = new HashMap <>();
377
396
for (PropertyDescriptor descriptor : pds ) {
378
397
descriptors .put (descriptor .getName (), descriptor );
379
398
}
@@ -388,21 +407,11 @@ protected Optional<E> addPersistentEntity(TypeInformation<?> typeInformation) {
388
407
entity .setPersistentPropertyAccessorFactory (persistentPropertyAccessorFactory );
389
408
}
390
409
391
- } catch (BeansException e ) {
392
- throw new MappingException (e .getMessage (), e );
410
+ return entity ;
393
411
} catch (RuntimeException e ) {
394
412
persistentEntities .remove (typeInformation );
395
413
throw e ;
396
- } finally {
397
- write .unlock ();
398
414
}
399
-
400
- // Inform listeners
401
- if (applicationEventPublisher != null && entity != null ) {
402
- applicationEventPublisher .publishEvent (new MappingContextEvent <>(this , entity ));
403
- }
404
-
405
- return Optional .of (entity );
406
415
}
407
416
408
417
/*
0 commit comments