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.
Persistence#createEntityManagerFactory(PersistenceConfiguration)
| Modifier and Type | Field and Description |
|---|---|
| public static final String | CACHE_MODE
String specifying a |
| public static final String | JDBC_DATASOURCE
An instance of |
| public static final String | JDBC_DRIVER
Fully qualified name of the JDBC driver class. |
| public static final String | JDBC_PASSWORD
Password for JDBC authentication. |
| public static final String | JDBC_URL
JDBC URL. |
| public static final String | JDBC_USER
Username for JDBC authentication. |
| private String | |
| public static final String | LOCK_TIMEOUT
Default pessimistic lock timeout hint. |
| private final List | |
| private final List | |
| private final String | |
| private String | |
| private final Map | |
| private String | |
| public static final String | QUERY_TIMEOUT
Default query timeout hint. |
| public static final String | SCHEMAGEN_CREATE_SCRIPT_SOURCE
An application-provided SQL script to be executed when the schema is created. |
| public static final String | SCHEMAGEN_CREATE_SOURCE
The source of artifacts to be created. |
| public static final String | SCHEMAGEN_CREATE_TARGET
The provider-generated SQL script which creates the schema when jakarta.persistence.schema-generation.scripts.action is set. |
| public static final String | SCHEMAGEN_DATABASE_ACTION
The action to be performed against the database. |
| public static final String | SCHEMAGEN_DROP_SCRIPT_SOURCE
An application-provided SQL script to be executed when the schema is dropped. |
| public static final String | SCHEMAGEN_DROP_SOURCE
The source of artifacts to be dropped. |
| public static final String | SCHEMAGEN_DROP_TARGET
The provider-generated SQL script which drops the schema when jakarta.persistence.schema-generation.scripts.action is set. |
| public static final String | SCHEMAGEN_SCRIPTS_ACTION
The action to be generated as a SQL script. |
| private SharedCacheMode | |
| private PersistenceUnitTransactionType | |
| public static final String | VALIDATION_FACTORY
An instance of |
| public static final String | VALIDATION_GROUP_PRE_PERSIST
Target groups for validation at |
| public static final String | VALIDATION_GROUP_PRE_REMOVE
Target groups for validation at |
| public static final String | VALIDATION_GROUP_PRE_UPDATE
Target groups for validation at |
| private ValidationMode |
| Access | Constructor and Description |
|---|---|
| public | PersistenceConfiguration(String
the name of the persistence unit, which may be used by
the persistence provider for logging and error reporting name)Create a new empty configuration. |
| Modifier and Type | Method and Description |
|---|---|
| public EntityManagerFactory | |
| public PersistenceConfiguration | Returns: this configurationthe JNDI name of a JTA datasource dataSourceJndiName)Specify the JNDI name of a JTA |
| public String | Returns: the configured JTA datasource, if any, or nullThe JNDI name of a JTA |
| public PersistenceConfiguration | Returns: this configurationthe managed class managedClass)Add a managed class (an |
| public List | Returns: all configured managed classesThe configured managed classes, that is, a list of classes
annotated |
| public PersistenceConfiguration | Returns: this configurationthe resource path of the mapping file name)Add the path of an XML mapping file loaded as a resource to the configuration. |
| public List | Returns: all configured mapping file resource pathsThe configured resource paths of XML mapping files. |
| public String | Returns: the name of the persistence unit.The name of the persistence unit, which may be used by the persistence provider for logging and error reporting. |
| public PersistenceConfiguration | Returns: this configurationthe JNDI name of a non-JTA datasource dataSourceJndiName)Specify the JNDI name of a non-JTA |
| public String | Returns: the configured non-JTA datasource, if any, or nullThe JNDI name of a non-JTA |
| public PersistenceConfiguration | Returns: this configurationthe properties properties)Set multiple properties of this persistence unit. |
| public Map | |
| public PersistenceConfiguration | |
| public PersistenceConfiguration | |
| public String | Returns: the qualified name of the persistence provider class.The fully-qualified name of a concrete class implementing
|
| public PersistenceConfiguration | Returns: this configurationthe shared cache mode sharedCacheMode)Specify the shared cache mode for the persistence unit. |
| public SharedCacheMode | |
| public PersistenceConfiguration | Returns: this configurationthe transaction type transactionType)Specify the transaction type for the persistence unit. |
| public PersistenceUnitTransactionType | |
| public PersistenceConfiguration | Returns: this configurationthe shared cache mode validationMode)Specify the validation mode for the persistence unit. |
| public ValidationMode |
| CACHE_MODE | back to summary |
|---|---|
| public static final String CACHE_MODE String specifying a Defined for use with
| |
| JDBC_DATASOURCE | back to summary |
|---|---|
| public static final String JDBC_DATASOURCE An instance of | |
| JDBC_DRIVER | back to summary |
|---|---|
| public static final String JDBC_DRIVER Fully qualified name of the JDBC driver class. | |
| JDBC_PASSWORD | back to summary |
|---|---|
| public static final String JDBC_PASSWORD Password for JDBC authentication. | |
| JDBC_URL | back to summary |
|---|---|
| public static final String JDBC_URL JDBC URL. | |
| JDBC_USER | back to summary |
|---|---|
| public static final String JDBC_USER Username for JDBC authentication. | |
| jtaDataSource | back to summary |
|---|---|
| private String jtaDataSource | |
| LOCK_TIMEOUT | back to summary |
|---|---|
| public static final String LOCK_TIMEOUT Default pessimistic lock timeout hint. | |
| managedClasses | back to summary |
|---|---|
| private final List<Class<?>> managedClasses | |
| mappingFileNames | back to summary |
|---|---|
| private final List<String> mappingFileNames | |
| name | back to summary |
|---|---|
| private final String name | |
| nonJtaDataSource | back to summary |
|---|---|
| private String nonJtaDataSource | |
| properties | back to summary |
|---|---|
| private final Map<String, Object> properties | |
| provider | back to summary |
|---|---|
| private String provider | |
| QUERY_TIMEOUT | back to summary |
|---|---|
| public static final String QUERY_TIMEOUT Default query timeout hint. | |
| SCHEMAGEN_CREATE_SCRIPT_SOURCE | back to summary |
|---|---|
| public static final String SCHEMAGEN_CREATE_SCRIPT_SOURCE An application-provided SQL script to be executed when the schema is created. | |
| SCHEMAGEN_CREATE_SOURCE | back to summary |
|---|---|
| public static final String SCHEMAGEN_CREATE_SOURCE The source of artifacts to be created. Standard sources are: The location of the script source is specified by jakarta.persistence.schema-generation.create-script-source. | |
| SCHEMAGEN_CREATE_TARGET | back to summary |
|---|---|
| public static final String SCHEMAGEN_CREATE_TARGET The provider-generated SQL script which creates the schema when jakarta.persistence.schema-generation.scripts.action is set. | |
| SCHEMAGEN_DATABASE_ACTION | back to summary |
|---|---|
| public static final String SCHEMAGEN_DATABASE_ACTION The action to be performed against the database. Standard actions are: | |
| SCHEMAGEN_DROP_SCRIPT_SOURCE | back to summary |
|---|---|
| public static final String SCHEMAGEN_DROP_SCRIPT_SOURCE An application-provided SQL script to be executed when the schema is dropped. | |
| SCHEMAGEN_DROP_SOURCE | back to summary |
|---|---|
| public static final String SCHEMAGEN_DROP_SOURCE The source of artifacts to be dropped. Standard sources are: The location of the script source is specified by jakarta.persistence.schema-generation.drop-script-source. | |
| SCHEMAGEN_DROP_TARGET | back to summary |
|---|---|
| public static final String SCHEMAGEN_DROP_TARGET The provider-generated SQL script which drops the schema when jakarta.persistence.schema-generation.scripts.action is set. | |
| SCHEMAGEN_SCRIPTS_ACTION | back to summary |
|---|---|
| public static final 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: | |
| sharedCacheMode | back to summary |
|---|---|
| private SharedCacheMode sharedCacheMode | |
| transactionType | back to summary |
|---|---|
| private PersistenceUnitTransactionType transactionType | |
| VALIDATION_FACTORY | back to summary |
|---|---|
| public static final String VALIDATION_FACTORY An instance of | |
| VALIDATION_GROUP_PRE_PERSIST | back to summary |
|---|---|
| public static final String VALIDATION_GROUP_PRE_PERSIST Target groups for validation at | |
| VALIDATION_GROUP_PRE_REMOVE | back to summary |
|---|---|
| public static final String VALIDATION_GROUP_PRE_REMOVE Target groups for validation at | |
| VALIDATION_GROUP_PRE_UPDATE | back to summary |
|---|---|
| public static final String VALIDATION_GROUP_PRE_UPDATE Target groups for validation at | |
| validationMode | back to summary |
|---|---|
| private ValidationMode validationMode | |
| PersistenceConfiguration | back to summary |
|---|---|
| public PersistenceConfiguration(String name) Create a new empty configuration. An empty configuration does not
typically hold enough information for successful invocation of
| |
| createEntityManagerFactory | back to summary |
|---|---|
| public EntityManagerFactory createEntityManagerFactory() Create a new
| |
| jtaDataSource | back to summary |
|---|---|
| public PersistenceConfiguration jtaDataSource(String dataSourceJndiName) Specify the JNDI name of a JTA
| |
| jtaDataSource | back to summary |
|---|---|
| public String jtaDataSource() The JNDI name of a JTA
| |
| managedClass | back to summary |
|---|---|
| public PersistenceConfiguration managedClass(Class<?> managedClass) Add a managed class (an
| |
| managedClasses | back to summary |
|---|---|
| public List The configured managed classes, that is, a list of classes
annotated | |
| mappingFile | back to summary |
|---|---|
| public PersistenceConfiguration mappingFile(String name) Add the path of an XML mapping file loaded as a resource to the configuration.
| |
| mappingFiles | back to summary |
|---|---|
| public List The configured resource paths of XML mapping files. | |
| name | back to summary |
|---|---|
| public String name() The name of the persistence unit, which may be used by the persistence provider for logging and error reporting.
| |
| nonJtaDataSource | back to summary |
|---|---|
| public PersistenceConfiguration nonJtaDataSource(String dataSourceJndiName) Specify the JNDI name of a non-JTA
| |
| nonJtaDataSource | back to summary |
|---|---|
| public String nonJtaDataSource() The JNDI name of a non-JTA
| |
| properties | back to summary |
|---|---|
| public PersistenceConfiguration properties(Map<String, ?> properties) Set multiple properties of this persistence unit.
| |
| properties | back to summary |
|---|---|
| public Map Standard and vendor-specific property settings. | |
| property | back to summary |
|---|---|
| public PersistenceConfiguration property(String name, Object value) Set a property of this persistence unit.
| |
| provider | back to summary |
|---|---|
| public PersistenceConfiguration provider(String providerClassName) Specify the persistence provider.
| |
| provider | back to summary |
|---|---|
| public String provider() The fully-qualified name of a concrete class implementing
| |
| sharedCacheMode | back to summary |
|---|---|
| public PersistenceConfiguration sharedCacheMode(SharedCacheMode sharedCacheMode) Specify the shared cache mode for the persistence unit.
| |
| sharedCacheMode | back to summary |
|---|---|
| public SharedCacheMode sharedCacheMode() The shared cache mode. The default behavior is unspecified and provider-specific.
| |
| transactionType | back to summary |
|---|---|
| public PersistenceConfiguration transactionType(PersistenceUnitTransactionType transactionType) Specify the transaction type for the persistence unit.
| |
| transactionType | back to summary |
|---|---|
| public PersistenceUnitTransactionType transactionType() The transaction type.
| |
| validationMode | back to summary |
|---|---|
| public PersistenceConfiguration validationMode(ValidationMode validationMode) Specify the validation mode for the persistence unit.
| |
| validationMode | back to summary |
|---|---|
| public ValidationMode validationMode() The validation mode,
| |