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) {