- java.lang.Object
-
- jakarta.persistence.PersistenceConfiguration
-
public class PersistenceConfiguration extends java.lang.ObjectRepresents a configuration of a persistence unit, allowing programmatic creation of anEntityManagerFactory. The configuration options available via this API reflect the similarly-named elements of thepersistence.xmlfile.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
EntityManagerFactoryis required, a CDIProducermay be used to make theEntityManagerFactoryavailable as a CDI managed bean. {@snippet :- Since:
- 3.2
- See Also:
Persistence.createEntityManagerFactory(PersistenceConfiguration)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCACHE_MODEString specifying aSharedCacheMode.static java.lang.StringJDBC_DATASOURCEAn instance ofjavax.sql.DataSource.static java.lang.StringJDBC_DRIVERFully qualified name of the JDBC driver class.static java.lang.StringJDBC_PASSWORDPassword for JDBC authentication.static java.lang.StringJDBC_URLJDBC URL.static java.lang.StringJDBC_USERUsername for JDBC authentication.private java.lang.StringjtaDataSourcestatic java.lang.StringLOCK_TIMEOUTDefault pessimistic lock timeout hint.private java.util.List<java.lang.Class<?>>managedClassesprivate java.util.List<java.lang.String>mappingFileNamesprivate java.lang.Stringnameprivate java.lang.StringnonJtaDataSourceprivate java.util.Map<java.lang.String,java.lang.Object>propertiesprivate java.lang.Stringproviderstatic java.lang.StringQUERY_TIMEOUTDefault query timeout hint.static java.lang.StringSCHEMAGEN_CREATE_SCRIPT_SOURCEAn application-provided SQL script to be executed when the schema is created.static java.lang.StringSCHEMAGEN_CREATE_SOURCEThe source of artifacts to be created.static java.lang.StringSCHEMAGEN_CREATE_TARGETThe provider-generated SQL script which creates the schema when "jakarta.persistence.schema-generation.scripts.action" is set.static java.lang.StringSCHEMAGEN_DATABASE_ACTIONThe action to be performed against the database.static java.lang.StringSCHEMAGEN_DROP_SCRIPT_SOURCEAn application-provided SQL script to be executed when the schema is dropped.static java.lang.StringSCHEMAGEN_DROP_SOURCEThe source of artifacts to be dropped.static java.lang.StringSCHEMAGEN_DROP_TARGETThe provider-generated SQL script which drops the schema when "jakarta.persistence.schema-generation.scripts.action" is set.static java.lang.StringSCHEMAGEN_SCRIPTS_ACTIONThe action to be generated as a SQL script.private SharedCacheModesharedCacheModeprivate PersistenceUnitTransactionTypetransactionTypestatic java.lang.StringVALIDATION_FACTORYAn instance ofjakarta.validation.ValidatorFactory,static java.lang.StringVALIDATION_GROUP_PRE_PERSISTTarget groups for validation atPrePersist.static java.lang.StringVALIDATION_GROUP_PRE_REMOVETarget groups for validation atPreRemove.static java.lang.StringVALIDATION_GROUP_PRE_UPDATETarget groups for validation atPreUpdate.private ValidationModevalidationMode
-
Constructor Summary
Constructors Constructor Description PersistenceConfiguration(java.lang.String name)Create a new empty configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EntityManagerFactorycreateEntityManagerFactory()Create a newEntityManagerFactorybased on this configuration.java.lang.StringjtaDataSource()The JNDI name of a JTAjavax.sql.DataSource.PersistenceConfigurationjtaDataSource(java.lang.String dataSourceJndiName)Specify the JNDI name of a JTAjavax.sql.DataSource.PersistenceConfigurationmanagedClass(java.lang.Class<?> managedClass)java.util.List<java.lang.Class<?>>managedClasses()The configured managed classes, that is, a list of classes annotatedEntity,Embeddable,MappedSuperclass, orConverter.PersistenceConfigurationmappingFile(java.lang.String name)Add the path of an XML mapping file loaded as a resource to the configuration.java.util.List<java.lang.String>mappingFiles()The configured resource paths of XML mapping files.java.lang.Stringname()The name of the persistence unit, which may be used by the persistence provider for logging and error reporting.java.lang.StringnonJtaDataSource()The JNDI name of a non-JTAjavax.sql.DataSource.PersistenceConfigurationnonJtaDataSource(java.lang.String dataSourceJndiName)Specify the JNDI name of a non-JTAjavax.sql.DataSource.java.util.Map<java.lang.String,java.lang.Object>properties()Standard and vendor-specific property settings.PersistenceConfigurationproperties(java.util.Map<java.lang.String,?> properties)Set multiple properties of this persistence unit.PersistenceConfigurationproperty(java.lang.String name, java.lang.Object value)Set a property of this persistence unit.java.lang.Stringprovider()The fully-qualified name of a concrete class implementingPersistenceProvider.PersistenceConfigurationprovider(java.lang.String providerClassName)Specify the persistence provider.SharedCacheModesharedCacheMode()The shared cache mode.PersistenceConfigurationsharedCacheMode(SharedCacheMode sharedCacheMode)Specify the shared cache mode for the persistence unit.PersistenceUnitTransactionTypetransactionType()The transaction type.PersistenceConfigurationtransactionType(PersistenceUnitTransactionType transactionType)Specify the transaction type for the persistence unit.ValidationModevalidationMode()The validation mode,ValidationMode.AUTOby default.PersistenceConfigurationvalidationMode(ValidationMode validationMode)Specify the validation mode for the persistence unit.
-
-
-
Field Detail
-
JDBC_DRIVER
public static final java.lang.String JDBC_DRIVER
Fully qualified name of the JDBC driver class.- See Also:
- Constant Field Values
-
JDBC_URL
public static final java.lang.String JDBC_URL
JDBC URL.- See Also:
- Constant Field Values
-
JDBC_USER
public static final java.lang.String JDBC_USER
Username for JDBC authentication.- See Also:
- Constant Field Values
-
JDBC_PASSWORD
public static final java.lang.String JDBC_PASSWORD
Password for JDBC authentication.- See Also:
- Constant Field Values
-
JDBC_DATASOURCE
public static final java.lang.String JDBC_DATASOURCE
An instance ofjavax.sql.DataSource.- See Also:
- Constant Field Values
-
LOCK_TIMEOUT
public static final java.lang.String LOCK_TIMEOUT
Default pessimistic lock timeout hint.- See Also:
- Constant Field Values
-
QUERY_TIMEOUT
public static final java.lang.String QUERY_TIMEOUT
Default query timeout hint.- See Also:
- Constant Field Values
-
SCHEMAGEN_DATABASE_ACTION
public static final java.lang.String SCHEMAGEN_DATABASE_ACTION
The action to be performed against the database.Standard actions are:
none,create,drop,drop-and-create,validate.- See Also:
- Constant Field Values
-
SCHEMAGEN_SCRIPTS_ACTION
public static final java.lang.String SCHEMAGEN_SCRIPTS_ACTION
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.- See Also:
- Constant Field Values
-
SCHEMAGEN_CREATE_SOURCE
public static final java.lang.String SCHEMAGEN_CREATE_SOURCE
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".
- See Also:
- Constant Field Values
-
SCHEMAGEN_DROP_SOURCE
public static final java.lang.String SCHEMAGEN_DROP_SOURCE
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".
- See Also:
- Constant Field Values
-
SCHEMAGEN_CREATE_SCRIPT_SOURCE
public static final java.lang.String SCHEMAGEN_CREATE_SCRIPT_SOURCE
An application-provided SQL script to be executed when the schema is created.- See Also:
- Constant Field Values
-
SCHEMAGEN_DROP_SCRIPT_SOURCE
public static final java.lang.String SCHEMAGEN_DROP_SCRIPT_SOURCE
An application-provided SQL script to be executed when the schema is dropped.- See Also:
- Constant Field Values
-
SCHEMAGEN_CREATE_TARGET
public static final java.lang.String SCHEMAGEN_CREATE_TARGET
The provider-generated SQL script which creates the schema when "jakarta.persistence.schema-generation.scripts.action" is set.- See Also:
- Constant Field Values
-
SCHEMAGEN_DROP_TARGET
public static final java.lang.String SCHEMAGEN_DROP_TARGET
The provider-generated SQL script which drops the schema when "jakarta.persistence.schema-generation.scripts.action" is set.- See Also:
- Constant Field Values
-
VALIDATION_FACTORY
public static final java.lang.String VALIDATION_FACTORY
An instance ofjakarta.validation.ValidatorFactory,- See Also:
- Constant Field Values
-
VALIDATION_GROUP_PRE_PERSIST
public static final java.lang.String VALIDATION_GROUP_PRE_PERSIST
Target groups for validation atPrePersist.- See Also:
- Constant Field Values
-
VALIDATION_GROUP_PRE_UPDATE
public static final java.lang.String VALIDATION_GROUP_PRE_UPDATE
Target groups for validation atPreUpdate.- See Also:
- Constant Field Values
-
VALIDATION_GROUP_PRE_REMOVE
public static final java.lang.String VALIDATION_GROUP_PRE_REMOVE
Target groups for validation atPreRemove.- See Also:
- Constant Field Values
-
CACHE_MODE
public static final java.lang.String CACHE_MODE
String specifying aSharedCacheMode.Defined for use with
Persistence.createEntityManagerFactory(String, Map). Clients of thisPersistenceConfigurationclass should usesharedCacheMode(SharedCacheMode).- See Also:
- Constant Field Values
-
name
private final java.lang.String name
-
provider
private java.lang.String provider
-
jtaDataSource
private java.lang.String jtaDataSource
-
nonJtaDataSource
private java.lang.String nonJtaDataSource
-
sharedCacheMode
private SharedCacheMode sharedCacheMode
-
validationMode
private ValidationMode validationMode
-
transactionType
private PersistenceUnitTransactionType transactionType
-
managedClasses
private final java.util.List<java.lang.Class<?>> managedClasses
-
mappingFileNames
private final java.util.List<java.lang.String> mappingFileNames
-
properties
private final java.util.Map<java.lang.String,java.lang.Object> properties
-
-
Constructor Detail
-
PersistenceConfiguration
public PersistenceConfiguration(java.lang.String name)
Create a new empty configuration. An empty configuration does not typically hold enough information for successful invocation ofcreateEntityManagerFactory().- Parameters:
name- the name of the persistence unit, which may be used by the persistence provider for logging and error reporting
-
-
Method Detail
-
createEntityManagerFactory
public EntityManagerFactory createEntityManagerFactory()
Create a newEntityManagerFactorybased on this configuration.- Throws:
PersistenceException- if required configuration is missing or if the factory could not be created
-
name
public java.lang.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.
-
provider
public PersistenceConfiguration provider(java.lang.String providerClassName)
Specify the persistence provider.- Parameters:
providerClassName- the qualified name of the persistence provider class- Returns:
- this configuration
-
provider
public java.lang.String provider()
The fully-qualified name of a concrete class implementingPersistenceProvider.- Returns:
- the qualified name of the persistence provider class.
-
jtaDataSource
public PersistenceConfiguration jtaDataSource(java.lang.String dataSourceJndiName)
Specify the JNDI name of a JTAjavax.sql.DataSource.- Parameters:
dataSourceJndiName- the JNDI name of a JTA datasource- Returns:
- this configuration
-
jtaDataSource
public java.lang.String jtaDataSource()
The JNDI name of a JTAjavax.sql.DataSource.- Returns:
- the configured JTA datasource, if any, or null
-
nonJtaDataSource
public PersistenceConfiguration nonJtaDataSource(java.lang.String dataSourceJndiName)
Specify the JNDI name of a non-JTAjavax.sql.DataSource.- Parameters:
dataSourceJndiName- the JNDI name of a non-JTA datasource- Returns:
- this configuration
-
nonJtaDataSource
public java.lang.String nonJtaDataSource()
The JNDI name of a non-JTAjavax.sql.DataSource.- Returns:
- the configured non-JTA datasource, if any, or null
-
managedClass
public PersistenceConfiguration managedClass(java.lang.Class<?> managedClass)
- Parameters:
managedClass- the managed class- Returns:
- this configuration
-
managedClasses
public java.util.List<java.lang.Class<?>> managedClasses()
The configured managed classes, that is, a list of classes annotatedEntity,Embeddable,MappedSuperclass, orConverter.- Returns:
- all configured managed classes
-
mappingFile
public PersistenceConfiguration mappingFile(java.lang.String name)
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
-
mappingFiles
public java.util.List<java.lang.String> mappingFiles()
The configured resource paths of XML mapping files.- Returns:
- all configured mapping file resource paths
-
transactionType
public PersistenceConfiguration transactionType(PersistenceUnitTransactionType transactionType)
Specify the transaction type for the persistence unit.- Parameters:
transactionType- the transaction type- Returns:
- this configuration
-
transactionType
public PersistenceUnitTransactionType transactionType()
The transaction type.- 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
- If
-
sharedCacheMode
public PersistenceConfiguration sharedCacheMode(SharedCacheMode sharedCacheMode)
Specify the shared cache mode for the persistence unit.- Parameters:
sharedCacheMode- the shared cache mode- Returns:
- this configuration
-
sharedCacheMode
public SharedCacheMode sharedCacheMode()
The shared cache mode. The default behavior is unspecified and provider-specific.- Returns:
- the shared cache mode
-
validationMode
public PersistenceConfiguration validationMode(ValidationMode validationMode)
Specify the validation mode for the persistence unit.- Parameters:
validationMode- the shared cache mode- Returns:
- this configuration
-
validationMode
public ValidationMode validationMode()
The validation mode,ValidationMode.AUTOby default.- Returns:
- the validation mode
-
property
public PersistenceConfiguration property(java.lang.String name, java.lang.Object value)
Set a property of this persistence unit.- Parameters:
name- the property namevalue- the property value- Returns:
- this configuration
-
properties
public PersistenceConfiguration properties(java.util.Map<java.lang.String,?> properties)
Set multiple properties of this persistence unit.- Parameters:
properties- the properties- Returns:
- this configuration
-
properties
public java.util.Map<java.lang.String,java.lang.Object> properties()
Standard and vendor-specific property settings.- Returns:
- the configured properties
-
-