Interface PersistenceProvider
In Java SE, the Persistence class calls:
createEntityManagerFactory(String, Map)when the application program callsPersistence.createEntityManagerFactory(String, Map),createEntityManagerFactory(PersistenceConfiguration)when the application program callsPersistenceConfiguration.createEntityManagerFactory(),generateSchema(String, Map)when the application, program callsPersistence.generateSchema(String, Map),generateSchema(PersistenceConfiguration)when the application program callsPersistenceConfiguration.exportSchema(), andgetProviderUtil()to obtain aProviderUtil.
In a Jakarta EE environment, the container calls:
createContainerEntityManagerFactory(PersistenceUnitInfo, Map)to create anEntityManagerFactoryfor a container-managed persistence unit.generateSchema(PersistenceUnitInfo, Map)to delegate DDL schema management to the persistence provider, andgetClassTransformer(PersistenceUnitInfo, Map)to obtain a provider-suppliedClassTransformer.
- Since:
- 1.0
- API note:
- This is an SPI interface forming part of the Jakarta EE container / persistence provider contract. It is not intended for direct use by application programs.
-
Method Summary
Modifier and TypeMethodDescriptioncreateContainerEntityManagerFactory(PersistenceUnitInfo info, Map<?, ?> properties) Called by the Jakarta EE container to create a newEntityManagerFactoryfor the persistence unit with the given metadata, optionally specifying configuration properties which override the settings specified in the givenPersistenceUnitInfo.createEntityManagerFactory(PersistenceConfiguration configuration) Called byPersistenceclass to create a newEntityManagerFactoryfor a persistence unit with the given programmatic configuration.createEntityManagerFactory(String unitName, Map<?, ?> properties) Called byPersistenceclass to create a newEntityManagerFactoryfor the persistence unit with the given name, optionally specifying configuration properties which override the settings specified in thepersistence.xmlfile for the given persistence unit.booleangenerateSchema(PersistenceConfiguration configuration) Create database schemas and/or tables and/or create DDL scripts, as determined by the supplied properties.voidgenerateSchema(PersistenceUnitInfo info, Map<?, ?> properties) Create database schemas and/or tables and/or create DDL scripts, as determined by the supplied properties.booleangenerateSchema(String persistenceUnitName, Map<?, ?> properties) Create database schemas and/or tables and/or create DDL scripts, as determined by the supplied properties.getClassTransformer(PersistenceUnitInfo info, Map<?, ?> properties) Obtain a provider-supplied class transformer that is called for every new class definition or class redefinition performed by the class loader returned byPersistenceUnitInfo.getClassLoader().Return the utility interface implemented by the persistence provider.
-
Method Details
-
createEntityManagerFactory
@Nonnull EntityManagerFactory createEntityManagerFactory(@Nonnull String unitName, @Nullable Map<?, ?> properties) Called byPersistenceclass to create a newEntityManagerFactoryfor the persistence unit with the given name, optionally specifying configuration properties which override the settings specified in thepersistence.xmlfile for the given persistence unit.- Parameters:
unitName- the name of the persistence unitproperties- property settings for use by the persistence provider. These properties may be used to specify values for properties not specified in thepersistence.xmlfile for the given persistence unit or to override the values specified by the corresponding elements of thepersistence.xmlfile. The map may be null when no properties are specified.- Returns:
- a newly created
EntityManagerFactoryfor the named persistence unit, or null if the persistence unit configuration specified a different persistence provider - See Also:
-
createEntityManagerFactory
@Nonnull EntityManagerFactory createEntityManagerFactory(@Nonnull PersistenceConfiguration configuration) Called byPersistenceclass to create a newEntityManagerFactoryfor a persistence unit with the given programmatic configuration.- Parameters:
configuration- the configuration of the persistence unit- Returns:
- a newly created
EntityManagerFactoryfor the persistence unit with the given configuration, or null if the persistence unit configuration specified a different persistence provider - Throws:
IllegalStateException- if any required configuration is missing- Since:
- 3.2
- See Also:
-
createContainerEntityManagerFactory
@Nonnull EntityManagerFactory createContainerEntityManagerFactory(@Nonnull PersistenceUnitInfo info, @Nullable Map<?, ?> properties) Called by the Jakarta EE container to create a newEntityManagerFactoryfor the persistence unit with the given metadata, optionally specifying configuration properties which override the settings specified in the givenPersistenceUnitInfo.- If a Jakarta Validation provider is present in the classpath,
the container must pass the
ValidatorFactoryinstance as an entry in the given map with the keyPersistence.ValidationProperties.VALIDATION_FACTORY. - If the containing archive is a bean archive, the container
must pass the
BeanManagerinstance as an entry in the given map with the keyPersistence.BeanManagementProperties.BEAN_MANAGER.
- Parameters:
info- metadata describing the persistence unitproperties- integration-level property settings for use by the persistence provider. The given properties may include properties to control schema generation. The map may be null when no properties are specified.- Returns:
- a newly created
EntityManagerFactoryfor the persistence unit described by the given metadata
- If a Jakarta Validation provider is present in the classpath,
the container must pass the
-
generateSchema
Create database schemas and/or tables and/or create DDL scripts, as determined by the supplied properties.Called by the container when schema generation is to occur as a separate phase from the creation of the entity manager factory.
- Parameters:
info- metadata describing the persistence unitproperties- property settings for schema generation; these may include provider-specific properties- Throws:
PersistenceException- if insufficient or inconsistent configuration information is provided or if schema generation otherwise fails- Since:
- 2.1
-
generateSchema
Create database schemas and/or tables and/or create DDL scripts, as determined by the supplied properties.Called by the
Persistenceclass when schema generation is to occur as a separate phase from creation of the entity manager factory.- Parameters:
persistenceUnitName- the name of the persistence unitproperties- property settings for schema generation; these may include provider-specific properties. The values of these properties override any values configured elsewhere.- Returns:
- true if the schema was generated, otherwise false
- Throws:
PersistenceException- if insufficient or inconsistent configuration information is provided or if schema generation otherwise fails- Since:
- 2.1
-
generateSchema
Create database schemas and/or tables and/or create DDL scripts, as determined by the supplied properties.Called by the
Persistenceclass when schema generation is to occur as a separate phase from creation of the entity manager factory.- Parameters:
configuration- the configuration of the persistence unit- Returns:
- true if the schema was generated, otherwise false
- Throws:
PersistenceException- if insufficient or inconsistent configuration information is provided or if schema generation otherwise fails- Since:
- 4.0
-
getProviderUtil
Return the utility interface implemented by the persistence provider.- Returns:
- an instance of
ProviderUtil - Since:
- 2.0
-
getClassTransformer
@Nonnull ClassTransformer getClassTransformer(@Nonnull PersistenceUnitInfo info, @Nullable Map<?, ?> properties) Obtain a provider-supplied class transformer that is called for every new class definition or class redefinition performed by the class loader returned byPersistenceUnitInfo.getClassLoader(). The transformer has no effect on the class loader returned byPersistenceUnitInfo.getNewTempClassLoader().A class is transformed exactly once within a given classloading scope, regardless of how many persistence units it belongs to.
The given instance of
PersistenceUnitInfomay returnnullwhen any of the accessor methodsPersistenceUnitInfo.getClassLoader(),PersistenceUnitInfo.getJtaDataSource(), orPersistenceUnitInfo.getNonJtaDataSource()is called by an implementation of this method.If the container calls this method before invoking
createContainerEntityManagerFactory(PersistenceUnitInfo, Map)to create theEntityManagerFactory, then the transformer returned by this method is used instead of any transformer registered viaPersistenceUnitInfo.addTransformer(ClassTransformer). The container is not required to call this method.- Parameters:
info- metadata describing the persistence unitproperties- integration-level property settings for use by the persistence provider, which will not usually contain aValidatorFactoryorBeanManager.- Returns:
- a provider-supplied transformer that is later invoked by the container when a managed class belonging to the persistence unit is defined or redefined
- Since:
- 4.0
-