File tree 2 files changed +17
-4
lines changed
spring-data-jpa/src/main/java/org/springframework/data/jpa/repository
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 {
68
68
private final EntityGraphLookup entityGraphLookup ;
69
69
70
70
public JpaRepositoryContributor (AotRepositoryContext repositoryContext ) {
71
+
71
72
super (repositoryContext );
72
73
73
74
AotMetamodel amm = new AotMetamodel (repositoryContext .getResolvedTypes ());
@@ -78,6 +79,7 @@ public JpaRepositoryContributor(AotRepositoryContext repositoryContext) {
78
79
}
79
80
80
81
public JpaRepositoryContributor (AotRepositoryContext repositoryContext , EntityManagerFactory entityManagerFactory ) {
82
+
81
83
super (repositoryContext );
82
84
83
85
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) {
325
325
*/
326
326
public static class JpaRepositoryRegistrationAotProcessor extends RepositoryRegistrationAotProcessor {
327
327
328
+ String GENERATED_REPOSITORIES_JPA_USE_ENTITY_MANAGER = "spring.aot.jpa.repositories.use-entitymanager" ;
329
+
328
330
protected @ Nullable RepositoryContributor contribute (AotRepositoryContext repositoryContext ,
329
331
GenerationContext generationContext ) {
330
332
@@ -334,11 +336,20 @@ public static class JpaRepositoryRegistrationAotProcessor extends RepositoryRegi
334
336
return null ;
335
337
}
336
338
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
+ }
339
351
340
- return emf != null ? new JpaRepositoryContributor (repositoryContext , emf )
341
- : new JpaRepositoryContributor (repositoryContext );
352
+ return new JpaRepositoryContributor (repositoryContext );
342
353
}
343
354
}
344
355
}
You can’t perform that action at this time.
0 commit comments