PersistenceUnitManager interface.
Used as internal default by
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean .
Supports standard JPA scanning for persistence.xml files,
with configurable file locations, JDBC DataSource lookup and load-time weaving.
Builds a persistence unit based on the state of a PersistenceManagedTypes,
typically built using a PersistenceManagedTypesScanner.
The default XML file location is classpath*:META-INF/persistence.xml,
scanning for all matching files in the classpath (as defined in the JPA specification).
DataSource names are by default interpreted as JNDI names, and no load time weaving
is available (which requires weaving to be turned off in the persistence provider).
setPersistenceXmlLocations, setDataSourceLookup, setLoadTimeWeaver, org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setPersistenceUnitManager
| Modifier and Type | Field and Description |
|---|---|
| private DataSourceLookup | |
| private static final String | |
| public static final String | DEFAULT_PERSISTENCE_XML_LOCATION
Default location of the |
| private DataSource | |
| private DataSource | |
| private String | |
| private String | |
| private LoadTimeWeaver | |
| protected final Log | |
| private ManagedClassNameFilter | |
| private PersistenceManagedTypes | |
| private String[] | |
| public static final String | ORIGINAL_DEFAULT_PERSISTENCE_UNIT_NAME
Default persistence unit name. |
| public static final String | ORIGINAL_DEFAULT_PERSISTENCE_UNIT_ROOT_LOCATION
Default location for the persistence unit root URL: "classpath:", indicating the root of the classpath. |
| private String[] | |
| private static final String | |
| private final Set | |
| private final Map | |
| private PersistenceUnitPostProcessor[] | |
| private String[] | |
| private ResourcePatternResolver | |
| private SharedCacheMode | |
| private ValidationMode |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc.
This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| private void | |
| private SpringPersistenceUnitInfo | |
| private URL | Returns: the persistence unit root URL to pass to the JPA PersistenceProviderTry to determine the persistence unit root URL based on the given "defaultPersistenceUnitRootLocation". |
| public DataSourceLookup | getDataSourceLookup()
Return the JDBC DataSourceLookup that provides DataSources for the
persistence provider, resolving data source names in |
| public DataSource | getDefaultDataSource()
Return the JDBC DataSource that the JPA persistence provider is supposed to use
for accessing the database if none has been specified in |
| public DataSource | getDefaultJtaDataSource()
Return the JTA-aware DataSource that the JPA persistence provider is supposed to use
for accessing the database if none has been specified in |
| public LoadTimeWeaver | getLoadTimeWeaver()
Return the Spring LoadTimeWeaver to use for class instrumentation according to the JPA class transformer contract. |
| private Resource | getOrmXmlForDefaultPersistenceUnit()
Determine JPA's default "META-INF/orm.xml" resource for use with Spring's default persistence unit, if any. |
| protected final MutablePersistenceUnitInfo | Returns: the PersistenceUnitInfo in mutable form, ornull if not availablethe name of the desired persistence unit persistenceUnitName)Return the specified PersistenceUnitInfo from this manager's cache of processed persistence units, keeping it in the cache (i.e. not 'obtaining' it for use but rather just accessing it for post-processing). |
| public PersistenceUnitPostProcessor[] | getPersistenceUnitPostProcessors()
Return the PersistenceUnitPostProcessors to be applied to each PersistenceUnitInfo that has been parsed by this manager. |
| protected boolean | isPersistenceUnitOverrideAllowed()
Return whether an override of a same-named persistence unit is allowed. |
| public PersistenceUnitInfo | obtainDefaultPersistenceUnitInfo()
Implements org. |
| public PersistenceUnitInfo | obtainPersistenceUnitInfo(String
the name of the desired persistence unit persistenceUnitName)Implements org. |
| protected void | postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo
the chosen PersistenceUnitInfo, as read from pui)persistence.xml.
Passed in as MutablePersistenceUnitInfo.Hook method allowing subclasses to customize each PersistenceUnitInfo. |
| public void | preparePersistenceUnitInfos()
Prepare the PersistenceUnitInfos according to the configuration
of this manager: scanning for |
| private List | readPersistenceUnitInfos()
Read all persistence unit infos from |
| public void | setDataSourceLookup(DataSourceLookup dataSourceLookup)
Specify the JDBC DataSourceLookup that provides DataSources for the
persistence provider, resolving data source names in |
| public void | setDataSources(Map<String, DataSource> dataSources)
Specify the JDBC DataSources that the JPA persistence provider is supposed
to use for accessing the database, resolving data source names in
|
| public void | setDefaultDataSource(DataSource defaultDataSource)
Specify the JDBC DataSource that the JPA persistence provider is supposed to use
for accessing the database if none has been specified in |
| public void | setDefaultJtaDataSource(DataSource defaultJtaDataSource)
Specify the JDBC DataSource that the JPA persistence provider is supposed to use
for accessing the database if none has been specified in |
| public void | setDefaultPersistenceUnitName(String defaultPersistenceUnitName)
Specify the name of the default persistence unit, if any. |
| public void | setDefaultPersistenceUnitRootLocation(String defaultPersistenceUnitRootLocation)
Set the default persistence unit root location, to be applied if no unit-specific persistence unit root could be determined. |
| public void | setLoadTimeWeaver(LoadTimeWeaver
the loadTimeWeaver)LoadTimeWeaver instance (never null)Implements org. |
| public void | setManagedClassNameFilter(ManagedClassNameFilter
a predicate to filter entity classes managedClassNameFilter)Set the |
| public void | setManagedTypes(PersistenceManagedTypes
the managed types managedTypes)Set the |
| public void | setMappingResources(String... mappingResources)
Specify one or more mapping resources (equivalent to |
| public void | setPackagesToScan(String... packagesToScan)
Set whether to use Spring-based scanning for entity classes in the classpath
instead of using JPA's standard scanning of jar files with |
| public void | setPersistenceUnitPostProcessors(PersistenceUnitPostProcessor... postProcessors)
Set the PersistenceUnitPostProcessors to be applied to each PersistenceUnitInfo that has been parsed by this manager. |
| public void | setPersistenceXmlLocation(String persistenceXmlLocation)
Specify the location of the |
| public void | setPersistenceXmlLocations(String...
an array of Spring resource Strings
identifying the location of the persistenceXmlLocations)persistence.xml files to readSpecify multiple locations of |
| public void | setResourceLoader(ResourceLoader
the ResourceLoader object to be used by this object resourceLoader)Implements org. This might be a ResourcePatternResolver, which can be checked
through |
| public void | setSharedCacheMode(SharedCacheMode sharedCacheMode)
Specify the JPA 2.0 shared cache mode for all of this manager's persistence
units, overriding any value in |
| public void | setValidationMode(ValidationMode validationMode)
Specify the JPA 2.0 validation mode for all of this manager's persistence
units, overriding any value in |
| dataSourceLookup | back to summary |
|---|---|
| private DataSourceLookup dataSourceLookup | |
| DEFAULT_ORM_XML_RESOURCE | back to summary |
|---|---|
| private static final String DEFAULT_ORM_XML_RESOURCE | |
| DEFAULT_PERSISTENCE_XML_LOCATION | back to summary |
|---|---|
| public static final String DEFAULT_PERSISTENCE_XML_LOCATION Default location of the | |
| defaultDataSource | back to summary |
|---|---|
| private DataSource defaultDataSource
| |
| defaultJtaDataSource | back to summary |
|---|---|
| private DataSource defaultJtaDataSource
| |
| defaultPersistenceUnitName | back to summary |
|---|---|
| private String defaultPersistenceUnitName
| |
| defaultPersistenceUnitRootLocation | back to summary |
|---|---|
| private String defaultPersistenceUnitRootLocation
| |
| loadTimeWeaver | back to summary |
|---|---|
| private LoadTimeWeaver loadTimeWeaver
| |
| logger | back to summary |
|---|---|
| protected final Log logger | |
| managedClassNameFilter | back to summary |
|---|---|
| private ManagedClassNameFilter managedClassNameFilter
| |
| managedTypes | back to summary |
|---|---|
| private PersistenceManagedTypes managedTypes
| |
| mappingResources | back to summary |
|---|---|
| private String[] mappingResources
| |
| ORIGINAL_DEFAULT_PERSISTENCE_UNIT_NAME | back to summary |
|---|---|
| public static final String ORIGINAL_DEFAULT_PERSISTENCE_UNIT_NAME Default persistence unit name. | |
| ORIGINAL_DEFAULT_PERSISTENCE_UNIT_ROOT_LOCATION | back to summary |
|---|---|
| public static final String ORIGINAL_DEFAULT_PERSISTENCE_UNIT_ROOT_LOCATION Default location for the persistence unit root URL: "classpath:", indicating the root of the classpath. | |
| packagesToScan | back to summary |
|---|---|
| private String[] packagesToScan
| |
| PERSISTENCE_XML_FILENAME | back to summary |
|---|---|
| private static final String PERSISTENCE_XML_FILENAME | |
| persistenceUnitInfoNames | back to summary |
|---|---|
| private final Set<String> persistenceUnitInfoNames | |
| persistenceUnitInfos | back to summary |
|---|---|
| private final Map<String, PersistenceUnitInfo> persistenceUnitInfos | |
| persistenceUnitPostProcessors | back to summary |
|---|---|
| private PersistenceUnitPostProcessor[] persistenceUnitPostProcessors
| |
| persistenceXmlLocations | back to summary |
|---|---|
| private String[] persistenceXmlLocations | |
| resourcePatternResolver | back to summary |
|---|---|
| private ResourcePatternResolver resourcePatternResolver | |
| sharedCacheMode | back to summary |
|---|---|
| private SharedCacheMode sharedCacheMode
| |
| validationMode | back to summary |
|---|---|
| private ValidationMode validationMode
| |
| DefaultPersistenceUnitManager | back to summary |
|---|---|
| public DefaultPersistenceUnitManager() | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() Implements org. Doc from org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
| |
| applyManagedTypes | back to summary |
|---|---|
| private void applyManagedTypes(SpringPersistenceUnitInfo scannedUnit, PersistenceManagedTypes managedTypes) | |
| buildDefaultPersistenceUnitInfo | back to summary |
|---|---|
| private SpringPersistenceUnitInfo buildDefaultPersistenceUnitInfo() Perform Spring-based scanning for entity classes.
| |
| determineDefaultPersistenceUnitRootUrl | back to summary |
|---|---|
| private URL determineDefaultPersistenceUnitRootUrl() Try to determine the persistence unit root URL based on the given "defaultPersistenceUnitRootLocation".
| |
| getDataSourceLookup | back to summary |
|---|---|
| public DataSourceLookup getDataSourceLookup() Return the JDBC DataSourceLookup that provides DataSources for the
persistence provider, resolving data source names in
| |
| getDefaultDataSource | back to summary |
|---|---|
| public DataSource getDefaultDataSource() Return the JDBC DataSource that the JPA persistence provider is supposed to use
for accessing the database if none has been specified in
| |
| getDefaultJtaDataSource | back to summary |
|---|---|
| public DataSource getDefaultJtaDataSource() Return the JTA-aware DataSource that the JPA persistence provider is supposed to use
for accessing the database if none has been specified in
| |
| getLoadTimeWeaver | back to summary |
|---|---|
| public LoadTimeWeaver getLoadTimeWeaver() Return the Spring LoadTimeWeaver to use for class instrumentation according to the JPA class transformer contract.
| |
| getOrmXmlForDefaultPersistenceUnit | back to summary |
|---|---|
| private Resource getOrmXmlForDefaultPersistenceUnit() Determine JPA's default "META-INF/orm.xml" resource for use with Spring's default persistence unit, if any. Checks whether a "META-INF/orm.xml" file exists in the classpath and uses it if it is not co-located with a "META-INF/persistence.xml" file.
| |
| getPersistenceUnitInfo | back to summary |
|---|---|
| protected final MutablePersistenceUnitInfo getPersistenceUnitInfo(String persistenceUnitName) Return the specified PersistenceUnitInfo from this manager's cache of processed persistence units, keeping it in the cache (i.e. not 'obtaining' it for use but rather just accessing it for post-processing). This can be used in
| |
| getPersistenceUnitPostProcessors | back to summary |
|---|---|
| public PersistenceUnitPostProcessor[] getPersistenceUnitPostProcessors() Return the PersistenceUnitPostProcessors to be applied to each PersistenceUnitInfo that has been parsed by this manager.
| |
| isPersistenceUnitOverrideAllowed | back to summary |
|---|---|
| protected boolean isPersistenceUnitOverrideAllowed() Return whether an override of a same-named persistence unit is allowed. Default is | |
| obtainDefaultPersistenceUnitInfo | back to summary |
|---|---|
| public PersistenceUnitInfo obtainDefaultPersistenceUnitInfo() Implements org. Doc from org. Obtain the default PersistenceUnitInfo from this manager.
| |
| obtainPersistenceUnitInfo | back to summary |
|---|---|
| public PersistenceUnitInfo obtainPersistenceUnitInfo(String persistenceUnitName) Implements org. Doc from org. Obtain the specified PersistenceUnitInfo from this manager.
| |
| postProcessPersistenceUnitInfo | back to summary |
|---|---|
| protected void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) Hook method allowing subclasses to customize each PersistenceUnitInfo. The default implementation delegates to all registered PersistenceUnitPostProcessors. It is usually preferable to register further entity classes, jar files etc there rather than in a subclass of this manager, to be able to reuse the post-processors.
| |
| preparePersistenceUnitInfos | back to summary |
|---|---|
| public void preparePersistenceUnitInfos() Prepare the PersistenceUnitInfos according to the configuration
of this manager: scanning for PersistenceUnitInfos cannot be obtained before this preparation method has been invoked. | |
| readPersistenceUnitInfos | back to summary |
|---|---|
| private List Read all persistence unit infos from | |
| setDataSourceLookup | back to summary |
|---|---|
| public void setDataSourceLookup(DataSourceLookup dataSourceLookup) Specify the JDBC DataSourceLookup that provides DataSources for the
persistence provider, resolving data source names in Default is JndiDataSourceLookup, which resolves DataSource names as JNDI names (as defined by standard JPA). Specify a BeanFactoryDataSourceLookup instance if you want DataSource names to be resolved against Spring bean names. Alternatively, consider passing in a map from names to DataSource instances
via the "dataSources" property. If the | |
| setDataSources | back to summary |
|---|---|
| public void setDataSources(Map<String, DataSource> dataSources) Specify the JDBC DataSources that the JPA persistence provider is supposed
to use for accessing the database, resolving data source names in
The specified Map needs to define data source names for specific DataSource
objects, matching the data source names used in | |
| setDefaultDataSource | back to summary |
|---|---|
| public void setDefaultDataSource(DataSource defaultDataSource) Specify the JDBC DataSource that the JPA persistence provider is supposed to use
for accessing the database if none has been specified in In JPA speak, a DataSource passed in here will be uses as "nonJtaDataSource" on the PersistenceUnitInfo passed to the PersistenceProvider, provided that none has been registered before. | |
| setDefaultJtaDataSource | back to summary |
|---|---|
| public void setDefaultJtaDataSource(DataSource defaultJtaDataSource) Specify the JDBC DataSource that the JPA persistence provider is supposed to use
for accessing the database if none has been specified in In JPA speak, a DataSource passed in here will be uses as "jtaDataSource" on the PersistenceUnitInfo passed to the PersistenceProvider, provided that none has been registered before. | |
| setDefaultPersistenceUnitName | back to summary |
|---|---|
| public void setDefaultPersistenceUnitName(String defaultPersistenceUnitName) Specify the name of the default persistence unit, if any. Default is "default". Primarily applied to a scanned persistence unit without | |
| setDefaultPersistenceUnitRootLocation | back to summary |
|---|---|
| public void setDefaultPersistenceUnitRootLocation(String defaultPersistenceUnitRootLocation) Set the default persistence unit root location, to be applied if no unit-specific persistence unit root could be determined. Default is "classpath:", that is, the root of the current classpath (nearest root directory). To be overridden if unit-specific resolution does not work and the classpath root is not appropriate either. | |
| setLoadTimeWeaver | back to summary |
|---|---|
| public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) Implements org. Specify the Spring LoadTimeWeaver to use for class instrumentation according to the JPA class transformer contract. It is not required to specify a LoadTimeWeaver: Most providers will be able to provide a subset of their functionality without class instrumentation as well, or operate with their own VM agent specified on JVM startup. Furthermore, DefaultPersistenceUnitManager falls back to an InstrumentationLoadTimeWeaver if Spring's agent-based instrumentation is available at runtime. In terms of Spring-provided weaving options, the most important ones are
InstrumentationLoadTimeWeaver, which requires a Spring-specific (but very general)
VM agent specified on JVM startup, and ReflectiveLoadTimeWeaver, which interacts
with an underlying ClassLoader based on specific extended methods being available
on it (for example, interacting with Spring's TomcatInstrumentableClassLoader).
Consider using the
| |
| setManagedClassNameFilter | back to summary |
|---|---|
| public void setManagedClassNameFilter(ManagedClassNameFilter managedClassNameFilter) Set the
| |
| setManagedTypes | back to summary |
|---|---|
| public void setManagedTypes(PersistenceManagedTypes managedTypes) Set the
| |
| setMappingResources | back to summary |
|---|---|
| public void setMappingResources(String... mappingResources) Specify one or more mapping resources (equivalent to Note that mapping resources must be relative to the classpath root,
e.g. "META-INF/mappings.xml" or "com/mycompany/repository/mappings.xml",
so that they can be loaded through If no explicit mapping resources have been specified next to
Note that specifying an empty array/list here suppresses the default
| |
| setPackagesToScan | back to summary |
|---|---|
| public void setPackagesToScan(String... packagesToScan) Set whether to use Spring-based scanning for entity classes in the classpath
instead of using JPA's standard scanning of jar files with Default is none. Specify packages to search for autodetection of your entity
classes in the classpath. This is analogous to Spring's component-scan feature
( Consider setting a Such package scanning defines a "default persistence unit" in Spring, which
may live next to regularly defined units originating from Note: There may be limitations in comparison to regular JPA scanning.
In particular, JPA providers may pick up annotated packages for provider-specific
annotations only when driven by If no explicit | |
| setPersistenceUnitPostProcessors | back to summary |
|---|---|
| public void setPersistenceUnitPostProcessors(PersistenceUnitPostProcessor... postProcessors) Set the PersistenceUnitPostProcessors to be applied to each PersistenceUnitInfo that has been parsed by this manager. Such post-processors can, for example, register further entity classes and
jar files, in addition to the metadata read from | |
| setPersistenceXmlLocation | back to summary |
|---|---|
| public void setPersistenceXmlLocation(String persistenceXmlLocation) Specify the location of the Default is "classpath*:META-INF/persistence.xml". | |
| setPersistenceXmlLocations | back to summary |
|---|---|
| public void setPersistenceXmlLocations(String... persistenceXmlLocations) Specify multiple locations of Default is "classpath*:META-INF/persistence.xml".
| |
| setResourceLoader | back to summary |
|---|---|
| public void setResourceLoader(ResourceLoader resourceLoader) Implements org. Doc from org. Set the ResourceLoader that this object runs in. This might be a ResourcePatternResolver, which can be checked
through Invoked after population of normal bean properties but before an init callback
like InitializingBean's
| |
| setSharedCacheMode | back to summary |
|---|---|
| public void setSharedCacheMode(SharedCacheMode sharedCacheMode) Specify the JPA 2.0 shared cache mode for all of this manager's persistence
units, overriding any value in
| |
| setValidationMode | back to summary |
|---|---|
| public void setValidationMode(ValidationMode validationMode) Specify the JPA 2.0 validation mode for all of this manager's persistence
units, overriding any value in
| |