File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
spring-data-jpa/src/main/java/org/springframework/data/jpa/repository Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ public class JpaRepositoryContributor extends RepositoryContributor {
6868 private final EntityGraphLookup entityGraphLookup ;
6969
7070 public JpaRepositoryContributor (AotRepositoryContext repositoryContext ) {
71+
7172 super (repositoryContext );
7273
7374 AotMetamodel amm = new AotMetamodel (repositoryContext .getResolvedTypes ());
@@ -78,6 +79,7 @@ public JpaRepositoryContributor(AotRepositoryContext repositoryContext) {
7879 }
7980
8081 public JpaRepositoryContributor (AotRepositoryContext repositoryContext , EntityManagerFactory entityManagerFactory ) {
82+
8183 super (repositoryContext );
8284
8385 this .persistenceProvider = PersistenceProvider .fromEntityManagerFactory (entityManagerFactory );
Original file line number Diff line number Diff line change @@ -325,6 +325,8 @@ static boolean isActive(@Nullable ClassLoader classLoader) {
325325 */
326326 public static class JpaRepositoryRegistrationAotProcessor extends RepositoryRegistrationAotProcessor {
327327
328+ String GENERATED_REPOSITORIES_JPA_USE_ENTITY_MANAGER = "spring.aot.jpa.repositories.use-entitymanager" ;
329+
328330 protected @ Nullable RepositoryContributor contribute (AotRepositoryContext repositoryContext ,
329331 GenerationContext generationContext ) {
330332
@@ -334,11 +336,20 @@ public static class JpaRepositoryRegistrationAotProcessor extends RepositoryRegi
334336 return null ;
335337 }
336338
337- ConfigurableListableBeanFactory beanFactory = repositoryContext .getBeanFactory ();
338- EntityManagerFactory emf = beanFactory .getBeanProvider (EntityManagerFactory .class ).getIfAvailable ();
339+ boolean useEntityManager = Boolean .parseBoolean (
340+ repositoryContext .getEnvironment ().getProperty (GENERATED_REPOSITORIES_JPA_USE_ENTITY_MANAGER , "false" ));
341+
342+ if (useEntityManager ) {
343+
344+ ConfigurableListableBeanFactory beanFactory = repositoryContext .getBeanFactory ();
345+ EntityManagerFactory emf = beanFactory .getBeanProvider (EntityManagerFactory .class ).getIfAvailable ();
346+
347+ if (emf != null ) {
348+ return new JpaRepositoryContributor (repositoryContext , emf );
349+ }
350+ }
339351
340- return emf != null ? new JpaRepositoryContributor (repositoryContext , emf )
341- : new JpaRepositoryContributor (repositoryContext );
352+ return new JpaRepositoryContributor (repositoryContext );
342353 }
343354 }
344355}
You can’t perform that action at this time.
0 commit comments