Class PersistenceConfiguration

java.lang.Object
jakarta.persistence.PersistenceConfiguration

public class PersistenceConfiguration extends Object
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.

Since:
3.2
See Also: