Remove PersistentEntity from MappingContext upon mapping metadata initialization errors.

When an error happens inside the AbstractMappingContext, the caching sometimes gets corrupted. That's because some exceptions are caught, others are not. Instead, the error handling that clears out the cache needs to be shifted up one level, resulting in a simpler code block.

Closes #2329
Original pull request: #2367.
This commit is contained in:
Greg L. Turnquist
2021-05-03 07:58:15 -05:00
committed by Mark Paluch
parent edc71531a4
commit b05965f2b2

View File

@@ -378,25 +378,21 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
descriptors.put(descriptor.getName(), descriptor);
}
try {
PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE);
persistentPropertyCreator.addPropertiesForRemainingDescriptors();
PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE);
persistentPropertyCreator.addPropertiesForRemainingDescriptors();
entity.verify();
entity.verify();
if (persistentPropertyAccessorFactory.isSupported(entity)) {
entity.setPersistentPropertyAccessorFactory(persistentPropertyAccessorFactory);
}
} catch (RuntimeException e) {
persistentEntities.remove(typeInformation);
throw e;
if (persistentPropertyAccessorFactory.isSupported(entity)) {
entity.setPersistentPropertyAccessorFactory(persistentPropertyAccessorFactory);
}
} catch (BeansException e) {
throw new MappingException(e.getMessage(), e);
} catch (RuntimeException e) {
persistentEntities.remove(typeInformation);
throw e;
} finally {
write.unlock();
}