类 DefaultPersistenceUnitManager

    • 方法详细资料

      • setPersistenceXmlLocation

        public void setPersistenceXmlLocation​(String persistenceXmlLocation)
        Specify the location of the persistence.xml files to load. These can be specified as Spring resource locations and/or location patterns.

        Default is "classpath*:META-INF/persistence.xml".

      • setPersistenceXmlLocations

        public void setPersistenceXmlLocations​(String... persistenceXmlLocations)
        Specify multiple locations of persistence.xml files to load. These can be specified as Spring resource locations and/or location patterns.

        Default is "classpath*:META-INF/persistence.xml".

        参数:
        persistenceXmlLocations - an array of Spring resource Strings identifying the location of the persistence.xml files to read
      • setDefaultPersistenceUnitRootLocation

        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.

      • setPackagesToScan

        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 persistence.xml markers in them. In case of Spring-based scanning, no persistence.xml is necessary; all you need to do is to specify base packages to search here.

        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 (ClassPathBeanDefinitionScanner).

        Such package scanning defines a "default persistence unit" in Spring, which may live next to regularly defined units originating from persistence.xml. Its name is determined by setDefaultPersistenceUnitName(java.lang.String): by default, it's simply "default".

        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 persistence.xml. As of 4.1, Spring's scan can detect annotated packages as well if supported by the given JpaVendorAdapter (e.g. for Hibernate).

        If no explicit mapping resources have been specified in addition to these packages, this manager looks for a default META-INF/orm.xml file in the classpath, registering it as a mapping resource for the default unit if the mapping file is not co-located with a persistence.xml file (in which case we assume it is only meant to be used with the persistence units defined there, like in standard JPA).

        另请参阅:
        setDefaultPersistenceUnitName(java.lang.String), setMappingResources(java.lang.String...)
      • setMappingResources

        public void setMappingResources​(String... mappingResources)
        Specify one or more mapping resources (equivalent to <mapping-file> entries in persistence.xml) for the default persistence unit. Can be used on its own or in combination with entity scanning in the classpath, in both cases avoiding persistence.xml.

        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 ClassLoader.getResource.

        If no explicit mapping resources have been specified next to packages to scan, this manager looks for a default META-INF/orm.xml file in the classpath, registering it as a mapping resource for the default unit if the mapping file is not co-located with a persistence.xml file (in which case we assume it is only meant to be used with the persistence units defined there, like in standard JPA).

        Note that specifying an empty array/list here suppresses the default META-INF/orm.xml check. On the other hand, explicitly specifying META-INF/orm.xml here will register that file even if it happens to be co-located with a persistence.xml file.

        另请参阅:
        setDefaultPersistenceUnitName(java.lang.String), setPackagesToScan(java.lang.String...)
      • setDataSources

        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 persistence.xml against Spring-managed DataSources.

        The specified Map needs to define data source names for specific DataSource objects, matching the data source names used in persistence.xml. If not specified, data source names will be resolved as JNDI names instead (as defined by standard JPA).

        另请参阅:
        MapDataSourceLookup
      • getDataSourceLookup

        public DataSourceLookup getDataSourceLookup()
        Return the JDBC DataSourceLookup that provides DataSources for the persistence provider, resolving data source names in persistence.xml against Spring-managed DataSource instances.
      • setDefaultDataSource

        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 persistence.xml. This variant indicates no special transaction setup, i.e. typical resource-local.

        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.

        另请参阅:
        PersistenceUnitInfo.getNonJtaDataSource()
      • getDefaultDataSource

        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 persistence.xml.
      • setDefaultJtaDataSource

        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 persistence.xml. This variant indicates that JTA is supposed to be used as transaction type.

        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.

        另请参阅:
        PersistenceUnitInfo.getJtaDataSource()
      • getDefaultJtaDataSource

        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 persistence.xml.
      • setPersistenceUnitPostProcessors

        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 persistence.xml.

      • setLoadTimeWeaver

        public void setLoadTimeWeaver​(LoadTimeWeaver loadTimeWeaver)
        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 context:load-time-weaver XML tag for creating such a shared LoadTimeWeaver (autodetecting the environment by default).

        指定者:
        setLoadTimeWeaver 在接口中 LoadTimeWeaverAware
        参数:
        loadTimeWeaver - the LoadTimeWeaver instance (never null)
        另请参阅:
        InstrumentationLoadTimeWeaver, ReflectiveLoadTimeWeaver
      • getLoadTimeWeaver

        public LoadTimeWeaver getLoadTimeWeaver()
        Return the Spring LoadTimeWeaver to use for class instrumentation according to the JPA class transformer contract.
      • afterPropertiesSet

        public void afterPropertiesSet()
        从接口复制的说明: InitializingBean
        Invoked by the containing 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.

        指定者:
        afterPropertiesSet 在接口中 InitializingBean