JPA Class

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. {@snippet :

See Also:
createEntityManagerFactory()
Since:
JPA 3.2

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:
JPA 3.2

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

Public Static Fields

String specifying a SharedCacheMode.

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

Since:
JPA 3.2
An instance of javax.sql.DataSource.
Since:
JPA 3.2
Fully qualified name of the JDBC driver class.
Since:
JPA 3.2
Password for JDBC authentication.
Since:
JPA 3.2
JDBC URL.
Since:
JPA 3.2
Username for JDBC authentication.
Since:
JPA 3.2
Default pessimistic lock timeout hint.
Since:
JPA 3.2
Default query timeout hint.
Since:
JPA 3.2
An application-provided SQL script to be executed when the schema is created.
Since:
JPA 3.2
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 {@value #SCHEMAGEN_CREATE_SCRIPT_SOURCE}.

Since:
JPA 3.2
The provider-generated SQL script which creates the schema when {@value SCHEMAGEN_SCRIPTS_ACTION} is set.
Since:
JPA 3.2
The action to be performed against the database.

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

Since:
JPA 3.2
An application-provided SQL script to be executed when the schema is dropped.
Since:
JPA 3.2
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 {@value #SCHEMAGEN_DROP_SCRIPT_SOURCE}.

Since:
JPA 3.2
The provider-generated SQL script which drops the schema when {@value SCHEMAGEN_SCRIPTS_ACTION} is set.
Since:
JPA 3.2
The action to be generated as a SQL script.

The script is generated in the location specified by {@value #SCHEMAGEN_CREATE_TARGET} or {@value #SCHEMAGEN_DROP_TARGET}.

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

Since:
JPA 3.2
An instance of jakarta.validation.ValidatorFactory,
Since:
JPA 3.2
Target groups for validation at PrePersist.
Since:
JPA 3.2
Target groups for validation at PreRemove.
Since:
JPA 3.2
Target groups for validation at PreUpdate.
Since:
JPA 3.2

Method inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait