From 084b46036a371e5b1e77bb7dee55ba484ada9bd1 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 9 Aug 2018 12:09:54 +0200 Subject: [PATCH] DATACMNS-1369 - RepositoryFactoryBeanSupport now adds the aggregate root type to the MappingContext. We now eagerly look up the aggregate root type of a repository in the MappingContext. Some implementations might not have pre-populated the context with all entities and we need to make sure it knows about the aggregate root as other clients (e.g. the auditing subsystem) might only defensively access the entities via PersistentEntities which is not adding new entities to avoid store clashes. --- .../repository/core/support/RepositoryFactoryBeanSupport.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java index c74de18f5..534bdc50d 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java @@ -290,6 +290,10 @@ public abstract class RepositoryFactoryBeanSupport, .append(customImplementationFragment); this.repositoryMetadata = this.factory.getRepositoryMetadata(repositoryInterface); + + // Make sure the aggregate root type is present in the MappingContext (e.g. for auditing) + this.mappingContext.ifPresent(it -> it.getPersistentEntity(repositoryMetadata.getDomainType())); + this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse)); if (!lazyInit) {