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 241ecad40..d44437fe5 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 @@ -320,11 +320,11 @@ public abstract class RepositoryFactoryBeanSupport, this.repositoryMetadata = this.factory.getRepositoryMetadata(repositoryInterface); + this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse)); + // 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) { this.repository.get(); }