Class PersistenceConfiguration


  • public class PersistenceConfiguration
    extends java.lang.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. {@snippet :

    Since:
    3.2
    See Also:
    Persistence.createEntityManagerFactory(PersistenceConfiguration)
    • 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 of createEntityManagerFactory().
        Parameters:
        name - the name of the persistence unit, which may be used by the persistence provider for logging and error reporting
    • Method Detail

      • 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 implementing PersistenceProvider.
        Returns:
        the qualified name of the persistence provider class.
      • jtaDataSource

        public PersistenceConfiguration jtaDataSource​(java.lang.String dataSourceJndiName)
        Specify the JNDI name of a JTA javax.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 JTA javax.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-JTA javax.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-JTA javax.sql.DataSource.
        Returns:
        the configured non-JTA datasource, if any, or null
      • managedClasses

        public java.util.List<java.lang.Class<?>> managedClasses()
        The configured managed classes, that is, a list of classes annotated Entity, Embeddable, MappedSuperclass, or Converter.
        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
      • 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
      • property

        public PersistenceConfiguration property​(java.lang.String name,
                                                 java.lang.Object value)
        Set a property of this persistence unit.
        Parameters:
        name - the property name
        value - 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