From e1b158073228511b697ab8fb809c2c2e5aac0ad9 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sat, 27 Feb 2021 11:33:52 +0100 Subject: [PATCH] Polish "Allow to configure PersistenceUnitPostProcessor" This commit updates EntityManagerFactoryBuilder so that persistence unit post processors can be registered and applied when creating an EntityManagerFactory. See gh-25443 --- .../jpa/AbstractJpaAutoConfigurationTests.java | 2 +- .../boot/orm/jpa/EntityManagerFactoryBuilder.java | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java index 5880e30b49..167cb8cc98 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java index df47ec1881..edde2446d0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -108,9 +108,10 @@ public class EntityManagerFactoryBuilder { } /** - * Set the PersistenceUnitPostProcessors to be applied to the PersistenceUnitInfo used - * for creating this EntityManagerFactory. - * @param persistenceUnitPostProcessors internal persistence unit post processors + * Set the {@linkplain PersistenceUnitPostProcessor persistence unit post processors} + * to be applied to the PersistenceUnitInfo used for creating the + * {@link LocalContainerEntityManagerFactoryBean}. + * @param persistenceUnitPostProcessors the persistence unit post processors to use * @since 2.5.0 */ public void setPersistenceUnitPostProcessors(PersistenceUnitPostProcessor... persistenceUnitPostProcessors) { @@ -245,8 +246,10 @@ public class EntityManagerFactoryBuilder { if (EntityManagerFactoryBuilder.this.bootstrapExecutor != null) { entityManagerFactoryBean.setBootstrapExecutor(EntityManagerFactoryBuilder.this.bootstrapExecutor); } - entityManagerFactoryBean - .setPersistenceUnitPostProcessors(EntityManagerFactoryBuilder.this.persistenceUnitPostProcessors); + if (EntityManagerFactoryBuilder.this.persistenceUnitPostProcessors != null) { + entityManagerFactoryBean.setPersistenceUnitPostProcessors( + EntityManagerFactoryBuilder.this.persistenceUnitPostProcessors); + } return entityManagerFactoryBean; }