jakarta.persistence.PersistenceConfiguration
java.lang.Object
∟jakarta.persistence.PersistenceConfiguration
EntityManagerFactory. The configuration options available via this API reflect the similarly-named elements of the persistence.xml file. This API may not be used to configure a container-managed persistence unit. That is, the configured persistence unit should be considered a Java SE persistence unit, even when this API is used within the Jakarta EE environment.
If injection of the EntityManagerFactory is required, a CDI Producer may be used to make the EntityManagerFactory available as a CDI managed bean.
@Produces @ApplicationScoped @Documents EntityManagerFactory configure() { return new PersistenceConfiguration() .name("DocumentData") .nonJtaDataSource("java:global/jdbc/DocumentDatabase") .managedClass(Document.class) .createEntityManagerFactory(); }
Similarly, if injection of an EntityManager is required, a CDI Producer method/Disposer method pair may be used to make the EntityManager available as a CDI managed bean.
@Produces @TransactionScoped @Documents EntityManager create(@Documents EntityManagerFactory factory) { return factory.createEntityManager(); } void close(@Disposes @Documents EntityManager entityManager) { entityManager.close(); }
It is intended that persistence providers define subclasses of this class with vendor-specific configuration options. A provider must support configuration via any instance of this class or of any subclass of this class.
- See Also:
- Since:
- Jakarta Persistence (JPA) 3.2
Public Static Fields
Defined for use with Persistence.createEntityManagerFactory. Clients of this PersistenceConfiguration class should use sharedCacheMode.
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
Standard sources are: metadata, script, metadata-then-script, script-then-metadata.
The location of the script source is specified by "jakarta.persistence.schema-generation.create-script-source".
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
Standard actions are: none, create, drop, drop-and-create, validate.
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
Standard sources are: metadata, script, metadata-then-script, script-then-metadata.
The location of the script source is specified by "jakarta.persistence.schema-generation.drop-script-source".
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
The script is generated in the location specified by "jakarta.persistence.schema-generation.create-target" or "jakarta.persistence.schema-generation.drop-target".
Standard actions are: none, create, drop, drop-and-create.
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
- Since:
- Jakarta Persistence (JPA) 1.0
Public Constructors
String name)createEntityManagerFactory.- Parameters:
name- the name of the persistence unit, which may be used by the persistence provider for logging and error reporting
- Since:
- Jakarta Persistence (JPA) 1.0
Public Instance Methods
- Throws:
- if required configuration is missing or if the factory could not be created.PersistenceException
- Since:
- Jakarta Persistence (JPA) 1.0
- Parameters:
dataSourceJndiName- the JNDI name of a JTA datasource
- Returns:
- this configuration.
- Since:
- Jakarta Persistence (JPA) 1.0
String jtaDataSource()- Returns:
- the configured JTA datasource, if any, or null.
- Since:
- Jakarta Persistence (JPA) 1.0
- Parameters:
managedClass- the managed class
- Returns:
- this configuration.
- Since:
- Jakarta Persistence (JPA) 1.0
List<Class<?>> managedClasses()- Returns:
- all configured managed classes.
- Since:
- Jakarta Persistence (JPA) 1.0
- Parameters:
name- the resource path of the mapping file
- Returns:
- this configuration.
- Since:
- Jakarta Persistence (JPA) 1.0
List<String> mappingFiles()- Returns:
- all configured mapping file resource paths.
- Since:
- Jakarta Persistence (JPA) 1.0
String name()- Returns:
- the name of the persistence unit..
- Since:
- Jakarta Persistence (JPA) 1.0
- Parameters:
dataSourceJndiName- the JNDI name of a non-JTA datasource
- Returns:
- this configuration.
- Since:
- Jakarta Persistence (JPA) 1.0
String nonJtaDataSource()- Returns:
- the configured non-JTA datasource, if any, or null.
- Since:
- Jakarta Persistence (JPA) 1.0
- Parameters:
properties- the properties
- Returns:
- this configuration.
- Since:
- Jakarta Persistence (JPA) 1.0
Map<String,Object> properties()- Returns:
- the configured properties.
- Since:
- Jakarta Persistence (JPA) 1.0
- Parameters:
name- the property namevalue- the property value
- Returns:
- this configuration.
- Since:
- Jakarta Persistence (JPA) 1.0
- Parameters:
providerClassName- the qualified name of the persistence provider class
- Returns:
- this configuration.
- Since:
- Jakarta Persistence (JPA) 1.0
String provider()- Returns:
- the qualified name of the persistence provider class..
- Since:
- Jakarta Persistence (JPA) 1.0
- Parameters:
sharedCacheMode- the shared cache mode
- Returns:
- this configuration.
- Since:
- Jakarta Persistence (JPA) 1.0
provider-specific.- Returns:
- the shared cache mode.
- Since:
- Jakarta Persistence (JPA) 1.0
- Parameters:
transactionType- the transaction type
- Returns:
- this configuration.
- Since:
- Jakarta Persistence (JPA) 1.0
- If
PersistenceUnitTransactionType.JTA, a JTA data source must be provided viajtaDataSource, or by the container. - If
PersistenceUnitTransactionType.RESOURCE_LOCAL, database connection properties may be specified viaproperties, or a non-JTA datasource may be provided vianonJtaDataSource.
- Returns:
- the transaction type.
- Since:
- Jakarta Persistence (JPA) 1.0
- Parameters:
validationMode- the shared cache mode
- Returns:
- this configuration.
- Since:
- Jakarta Persistence (JPA) 1.0
- Returns:
- the validation mode.
- Since:
- Jakarta Persistence (JPA) 1.0
Additional JDK methods inherited from java.lang.Object
clone(), equals(Object), finalize(), getClass(), hashCode(), notify(), notifyAll(), toString(), wait(), wait(long), wait(long,int), wait0(long)