Class PersistenceConfiguration
- All Implemented Interfaces:
Persistence.BeanManagementProperties, Persistence.CacheProperties, Persistence.ConnectionProperties, Persistence.DatabaseProperties, Persistence.JdbcProperties, Persistence.SchemaManagementProperties, Persistence.ValidationProperties
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("DocumentData")
.nonJtaDataSource("java:global/jdbc/DocumentDatabase")
.defaultToOneFetchType(FetchType.LAZY)
.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.
- Since:
- 3.2
- See Also:
-
Field Summary
Fields inherited from interface Persistence.BeanManagementProperties
BEAN_MANAGERFields inherited from interface Persistence.CacheProperties
CACHE_MODEFields inherited from interface Persistence.ConnectionProperties
JDBC_DATASOURCE, JDBC_DRIVER, JDBC_PASSWORD, JDBC_URL, JDBC_USERFields inherited from interface Persistence.DatabaseProperties
DATABASE_MAJOR_VERSION, DATABASE_MINOR_VERSION, DATABASE_PRODUCT_NAMEFields inherited from interface Persistence.JdbcProperties
JDBC_BATCH_SIZE, JDBC_FETCH_SIZE, LOCK_TIMEOUT, QUERY_TIMEOUTFields inherited from interface Persistence.SchemaManagementProperties
SCHEMAGEN_CONNECTION, SCHEMAGEN_CREATE_SCHEMAS, SCHEMAGEN_CREATE_SCRIPT_SOURCE, SCHEMAGEN_CREATE_SOURCE, SCHEMAGEN_CREATE_TARGET, SCHEMAGEN_DATABASE_ACTION, SCHEMAGEN_DROP_SCRIPT_SOURCE, SCHEMAGEN_DROP_SOURCE, SCHEMAGEN_DROP_TARGET, SCHEMAGEN_LOAD_SCRIPT_SOURCE, SCHEMAGEN_SCRIPTS_ACTIONFields inherited from interface Persistence.ValidationProperties
VALIDATION_FACTORY, VALIDATION_GROUP_PRE_DELETE, VALIDATION_GROUP_PRE_INSERT, VALIDATION_GROUP_PRE_MERGE, VALIDATION_GROUP_PRE_PERSIST, VALIDATION_GROUP_PRE_REMOVE, VALIDATION_GROUP_PRE_UPDATE, VALIDATION_GROUP_PRE_UPSERT, VALIDATION_MODE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate a newEntityManagerFactorybased on this configuration.The default fetch type,FetchType.EAGERby default.defaultToOneFetchType(FetchType defaultToOneFetchType) Specify the default fetch type for one-to-one and many-to-one associations.voidExecute the schema management action specified by the propertyPersistence.SchemaManagementProperties.SCHEMAGEN_DATABASE_ACTIONorPersistence.SchemaManagementProperties.SCHEMAGEN_SCRIPTS_ACTION, or byschemaManagementDatabaseAction(SchemaManagementAction)orschemaManagementScriptsAction(SchemaManagementAction)without creating anEntityManagerFactory.The schema management action to be performed by generated DDL scripts.The JNDI name of a JTAjavax.sql.DataSource.jtaDataSource(String dataSourceJndiName) Specify the JNDI name of a JTAjavax.sql.DataSource.managedClass(Class<?> managedClass) The configured managed classes, that is, a list of classes annotatedEntity,Embeddable,MappedSuperclass, orConverter.mappingFile(String name) Add the path of an XML mapping file loaded as a resource to the configuration.The configured resource paths of XML mapping files.name()The name of the persistence unit, which may be used by the persistence provider for logging and error reporting.The JNDI name of a non-JTAjavax.sql.DataSource.nonJtaDataSource(String dataSourceJndiName) Specify the JNDI name of a non-JTAjavax.sql.DataSource.Standard and vendor-specific property settings.properties(Map<String, ?> properties) Set multiple properties of this persistence unit.Set a property of this persistence unit.provider()The fully-qualified name of a concrete class implementingPersistenceProvider.Specify the persistence provider.The schema management action to be performed against the database.Set the schema management action to be performed against the database.Set the schema management action to be performed by generated DDL scripts.The shared cache mode.sharedCacheMode(SharedCacheMode sharedCacheMode) Specify the shared cache mode for the persistence unit.The transaction type.transactionType(PersistenceUnitTransactionType transactionType) Specify the transaction type for the persistence unit.The validation mode,ValidationMode.AUTOby default.validationMode(ValidationMode validationMode) Specify the validation mode for the persistence unit.
-
Constructor Details
-
PersistenceConfiguration
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 Details
-
createEntityManagerFactory
Create a newEntityManagerFactorybased on this configuration.- Throws:
PersistenceException- if required configuration is missing or if the factory could not be created
-
exportSchema
public void exportSchema()Execute the schema management action specified by the propertyPersistence.SchemaManagementProperties.SCHEMAGEN_DATABASE_ACTIONorPersistence.SchemaManagementProperties.SCHEMAGEN_SCRIPTS_ACTION, or byschemaManagementDatabaseAction(SchemaManagementAction)orschemaManagementScriptsAction(SchemaManagementAction)without creating anEntityManagerFactory.- Throws:
PersistenceException- if insufficient or inconsistent configuration information is provided or if schema generation otherwise fails.- Since:
- 4.0
-
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
Specify the persistence provider.- Parameters:
providerClassName- the qualified name of the persistence provider class- Returns:
- this configuration
-
provider
The fully-qualified name of a concrete class implementingPersistenceProvider.- Returns:
- the qualified name of the persistence provider class.
-
jtaDataSource
Specify the JNDI name of a JTAjavax.sql.DataSource.- Parameters:
dataSourceJndiName- the JNDI name of a JTA datasource- Returns:
- this configuration
-
jtaDataSource
The JNDI name of a JTAjavax.sql.DataSource.- Returns:
- the configured JTA datasource, if any, or null
-
nonJtaDataSource
Specify the JNDI name of a non-JTAjavax.sql.DataSource.- Parameters:
dataSourceJndiName- the JNDI name of a non-JTA datasource- Returns:
- this configuration
-
nonJtaDataSource
The JNDI name of a non-JTAjavax.sql.DataSource.- Returns:
- the configured non-JTA datasource, if any, or null
-
managedClass
- Parameters:
managedClass- the managed class- Returns:
- this configuration
-
managedClasses
The configured managed classes, that is, a list of classes annotatedEntity,Embeddable,MappedSuperclass, orConverter.- Returns:
- all configured managed classes
-
mappingFile
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
-
transactionType
Specify the transaction type for the persistence unit.- Parameters:
transactionType- the transaction type- Returns:
- this configuration
-
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
-
validationMode
Specify the validation mode for the persistence unit.- Parameters:
validationMode- the shared cache mode- Returns:
- this configuration
-
validationMode
The validation mode,ValidationMode.AUTOby default.- Returns:
- the validation mode
-
defaultToOneFetchType
Specify the default fetch type for one-to-one and many-to-one associations. The given fetch type value must beFetchType.EAGERorFetchType.LAZY.- Parameters:
defaultToOneFetchType- the default fetch type- Returns:
- this configuration
- Since:
- 4.0
-
defaultToOneFetchType
The default fetch type,FetchType.EAGERby default.- Since:
- 4.0
-
schemaManagementDatabaseAction
Set the schema management action to be performed against the database.- Parameters:
action- The schema management action to be performed- Since:
- 4.0
- See Also:
-
schemaManagementDatabaseAction
The schema management action to be performed against the database.- Returns:
- The schema management action
- Since:
- 4.0
- See Also:
-
schemaManagementScriptsAction
Set the schema management action to be performed by generated DDL scripts.- Parameters:
action- The schema management action to be performed- Since:
- 4.0
- See Also:
-
getSchemaManagementScriptsAction
The schema management action to be performed by generated DDL scripts.- Returns:
- The schema management action
- Since:
- 4.0
- See Also:
-
property
Set a property of this persistence unit.- Parameters:
name- the property namevalue- the property value- Returns:
- this configuration
-
properties
Set multiple properties of this persistence unit.- Parameters:
properties- the properties- Returns:
- this configuration
-
properties
-