Jakarta Persistence (JPA) Class

jakarta.persistence.PersistenceConfiguration

java.lang.Object
  jakarta.persistence.PersistenceConfiguration

Represents a configuration of a persistence unit, allowing programmatic creation of an 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

String specifying a SharedCacheMode.

Defined for use with Persistence.createEntityManagerFactory. Clients of this PersistenceConfiguration class should use sharedCacheMode.

Since:
Jakarta Persistence (JPA) 1.0
An instance of javax.sql.DataSource.
Since:
Jakarta Persistence (JPA) 1.0
Fully qualified name of the JDBC driver class.
Since:
Jakarta Persistence (JPA) 1.0
Password for JDBC authentication.
Since:
Jakarta Persistence (JPA) 1.0
JDBC URL.
Since:
Jakarta Persistence (JPA) 1.0
Username for JDBC authentication.
Since:
Jakarta Persistence (JPA) 1.0
Default pessimistic lock timeout hint.
Since:
Jakarta Persistence (JPA) 1.0
Default query timeout hint.
Since:
Jakarta Persistence (JPA) 1.0
An application-provided SQL script to be executed when the schema is created.
Since:
Jakarta Persistence (JPA) 1.0
The source of artifacts to be created.

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
The provider-generated SQL script which creates the schema when "jakarta.persistence.schema-generation.scripts.action" is set.
Since:
Jakarta Persistence (JPA) 1.0
The action to be performed against the database.

Standard actions are: none, create, drop, drop-and-create, validate.

Since:
Jakarta Persistence (JPA) 1.0
An application-provided SQL script to be executed when the schema is dropped.
Since:
Jakarta Persistence (JPA) 1.0
The source of artifacts to be dropped.

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
The provider-generated SQL script which drops the schema when "jakarta.persistence.schema-generation.scripts.action" is set.
Since:
Jakarta Persistence (JPA) 1.0
The action to be generated as a SQL script.

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
An instance of jakarta.validation.ValidatorFactory,
Since:
Jakarta Persistence (JPA) 1.0
Target groups for validation at PrePersist.
Since:
Jakarta Persistence (JPA) 1.0
Target groups for validation at PreRemove.
Since:
Jakarta Persistence (JPA) 1.0
Target groups for validation at PreUpdate.
Since:
Jakarta Persistence (JPA) 1.0

Public Constructors

Create a new empty configuration.
An empty configuration does not typically hold enough information for successful invocation of 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

Create a new EntityManagerFactory based on this configuration.
Throws:
PersistenceException - if required configuration is missing or if the factory could not be created.
Since:
Jakarta Persistence (JPA) 1.0
PersistenceConfiguration jtaDataSource(String dataSourceJndiName)
Specify the JNDI name of a JTA javax.sql.DataSource.
Parameters:
dataSourceJndiName - the JNDI name of a JTA datasource
Returns:
this configuration.
Since:
Jakarta Persistence (JPA) 1.0
String jtaDataSource()
The JNDI name of a JTA javax.sql.DataSource.
Returns:
the configured JTA datasource, if any, or null.
Since:
Jakarta Persistence (JPA) 1.0
PersistenceConfiguration managedClass(Class<?> managedClass)
Add a managed class (an Entity, Embeddable, MappedSuperclass, or Converter) to the configuration.
Parameters:
managedClass - the managed class
Returns:
this configuration.
Since:
Jakarta Persistence (JPA) 1.0
List<Class<?>> managedClasses()
The configured managed classes, that is, a list of classes annotated Entity, Embeddable, MappedSuperclass, or Converter.
Returns:
all configured managed classes.
Since:
Jakarta Persistence (JPA) 1.0
Add the path of an XML mapping file loaded as a resource to the configuration.
Parameters:
name - the resource path of the mapping file
Returns:
this configuration.
Since:
Jakarta Persistence (JPA) 1.0
List<String> mappingFiles()
The configured resource paths of XML mapping files.
Returns:
all configured mapping file resource paths.
Since:
Jakarta Persistence (JPA) 1.0
String name()
The name of the persistence unit, which may be used by the persistence provider for logging and error reporting.
Returns:
the name of the persistence unit..
Since:
Jakarta Persistence (JPA) 1.0
PersistenceConfiguration nonJtaDataSource(String dataSourceJndiName)
Specify the JNDI name of a non-JTA javax.sql.DataSource.
Parameters:
dataSourceJndiName - the JNDI name of a non-JTA datasource
Returns:
this configuration.
Since:
Jakarta Persistence (JPA) 1.0
The JNDI name of a non-JTA javax.sql.DataSource.
Returns:
the configured non-JTA datasource, if any, or null.
Since:
Jakarta Persistence (JPA) 1.0
PersistenceConfiguration properties(Map<String,?> properties)
Set multiple properties of this persistence unit.
Parameters:
properties - the properties
Returns:
this configuration.
Since:
Jakarta Persistence (JPA) 1.0
Map<String,Object> properties()
Standard and vendor-specific property settings.
Returns:
the configured properties.
Since:
Jakarta Persistence (JPA) 1.0
PersistenceConfiguration property(String name, Object value)
Set a property of this persistence unit.
Parameters:
name - the property name
value - the property value
Returns:
this configuration.
Since:
Jakarta Persistence (JPA) 1.0
PersistenceConfiguration provider(String providerClassName)
Specify the persistence provider.
Parameters:
providerClassName - the qualified name of the persistence provider class
Returns:
this configuration.
Since:
Jakarta Persistence (JPA) 1.0
String provider()
The fully-qualified name of a concrete class implementing PersistenceProvider.
Returns:
the qualified name of the persistence provider class..
Since:
Jakarta Persistence (JPA) 1.0
Specify the shared cache mode for the persistence unit.
Parameters:
sharedCacheMode - the shared cache mode
Returns:
this configuration.
Since:
Jakarta Persistence (JPA) 1.0
The shared cache mode.
The default behavior is unspecified and provider-specific.
Returns:
the shared cache mode.
Since:
Jakarta Persistence (JPA) 1.0
Specify the transaction type for the persistence unit.
Parameters:
transactionType - the transaction type
Returns:
this configuration.
Since:
Jakarta Persistence (JPA) 1.0
Returns:
the transaction type.
Since:
Jakarta Persistence (JPA) 1.0
Specify the validation mode for the persistence unit.
Parameters:
validationMode - the shared cache mode
Returns:
this configuration.
Since:
Jakarta Persistence (JPA) 1.0
The validation mode, ValidationMode.AUTO by default.
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)