Browse Source

Revise setPersistenceUnitName javadoc

Closes gh-36205
pull/36209/head
Juergen Hoeller 5 days ago
parent
commit
22cf7958a5
  1. 8
      spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java
  2. 7
      spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java
  3. 14
      spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java

8
spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java

@ -171,10 +171,10 @@ public abstract class AbstractEntityManagerFactoryBean implements @@ -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) {

7
spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java

@ -141,9 +141,10 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage @@ -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

14
spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java

@ -127,11 +127,23 @@ public class LocalEntityManagerFactoryBean extends AbstractEntityManagerFactoryB @@ -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),

Loading…
Cancel
Save