Create PersistentEntities only for user class in case of proxy instance.

This commit makes sure to only create a PersistentEntity for an actual user type. Therefore ClassTypeInformation now considers the given type and not only the user one for both equals and hashcode. This makes sure we can distinguish TypeInformation for a proxy from the one of a user class.
The AbstractMapping context will take care of unpacking proxied types and registering the created entity for both the user as well as the proxy type information.
Prior to this commit build time generated proxy instances would have been able to pollute the context depending on the order they had been served by the initial entity set.

Closes #2485
Original pull request: #2486.
This commit is contained in:
Christoph Strobl
2021-10-21 16:00:25 +02:00
committed by Mark Paluch
parent 69397a11b2
commit c30f3fc8af
5 changed files with 357 additions and 1 deletions

View File

@@ -360,6 +360,17 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
return persistentEntity;
}
if(typeInformation.isProxyTypeInformation()) {
TypeInformation<?> userTypeInformation = typeInformation.getUserTypeInformation();
persistentEntity = persistentEntities.get(userTypeInformation);
if (persistentEntity != null) {
persistentEntities.put(typeInformation, persistentEntity);
return persistentEntity;
}
}
} finally {
read.unlock();
}
@@ -369,7 +380,10 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
try {
write.lock();
entity = doAddPersistentEntity(typeInformation);
entity = doAddPersistentEntity(typeInformation.getUserTypeInformation());
if(typeInformation.isProxyTypeInformation()) {
persistentEntities.put(typeInformation, Optional.of(entity));
}
} catch (BeansException e) {
throw new MappingException(e.getMessage(), e);