diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java index 83b72032644..53aa1ee9d4c 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java @@ -171,10 +171,10 @@ public abstract class AbstractEntityManagerFactoryBean implements } /** - * Specify the name of the EntityManagerFactory configuration. - *

Default is none, indicating the default EntityManagerFactory - * configuration. The persistence provider will throw an exception if - * ambiguous EntityManager configurations are found. + * Specify the name of the persistence unit configuration to use. + *

Default is none, indicating the default persistence unit configuration. + * The persistence provider will throw an exception if ambiguous persistence + * unit configurations are found. * @see jakarta.persistence.Persistence#createEntityManagerFactory(String) */ public void setPersistenceUnitName(@Nullable String persistenceUnitName) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java index 8b080269b49..87de3cc71da 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java @@ -141,9 +141,10 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage } /** - * Uses the specified persistence unit name as the name of the default - * persistence unit, if applicable. - *

NOTE: Only applied if no external PersistenceUnitManager specified. + * Specify the name of the persistence unit configuration to use. + *

Uses the specified persistence unit name as the name of the + * default persistence unit, if applicable. Otherwise, it selects + * among the available persistence units. * @see DefaultPersistenceUnitManager#setDefaultPersistenceUnitName */ @Override diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java index 615e8a0cc82..f6e8386dd3e 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java @@ -127,11 +127,23 @@ public class LocalEntityManagerFactoryBean extends AbstractEntityManagerFactoryB */ public PersistenceConfiguration getPersistenceConfiguration() { if (this.configuration == null) { - this.configuration = new PersistenceConfiguration(getPersistenceUnitName()); + String name = getPersistenceUnitName(); + Assert.state(name != null, "No persistenceUnitName set"); + this.configuration = new PersistenceConfiguration(name); } return this.configuration; } + /** + * Specify the name of the persistence unit configuration to use. + *

Uses the specified persistence unit name as the name of the local + * persistence unit built through {@link #getPersistenceConfiguration()}, if + * applicable. Otherwise, it selects among the available persistence units. + *

Note: This setter method is not meant to be used in combination with + * {@link #setPersistenceConfiguration} which derives the persistence unit + * name from the given {@link PersistenceConfiguration} instance instead. + * @see #getPersistenceConfiguration() + */ @Override public void setPersistenceUnitName(@Nullable String persistenceUnitName) { Assert.state(this.configuration == null || this.configuration.name().equals(persistenceUnitName),