Revise setPersistenceUnitName javadoc

Closes gh-36205
This commit is contained in:
Juergen Hoeller
2026-01-25 10:38:24 +01:00
parent ab314aadd9
commit 22cf7958a5
3 changed files with 21 additions and 8 deletions
@@ -171,10 +171,10 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
/**
* Specify the name of the EntityManagerFactory configuration.
* <p>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.
* <p>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) {
@@ -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.
* <p><b>NOTE: Only applied if no external PersistenceUnitManager specified.</b>
* Specify the name of the persistence unit configuration to use.
* <p>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
@@ -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.
* <p>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.
* <p>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),