Top Description Inners Fields Constructors Methods
jakarta.persistence

public Class Persistence

extends Object
Class Inheritance
Imports
java.util.List, .Map, .Set, .HashSet, jakarta.persistence.spi.PersistenceProvider, .PersistenceProviderResolver, .PersistenceProviderResolverHolder, .LoadState

Bootstrap class used to obtain an EntityManagerFactory in Java SE environments. It may also be used to cause schema generation to occur.

The Persistence class is available in a Jakarta EE container environment as well; however, support for the Java SE bootstrapping APIs is not required in container environments.

The Persistence class is used to obtain a PersistenceUtil instance in both Jakarta EE and Java SE environments.

Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Persistence.PersistenceUtilImpl

Implementation of the PersistenceUtil interface

Field Summary

Modifier and TypeField and Description
public static final String
PERSISTENCE_PROVIDER

Deprecated for removal since 3.2. TODO: Either change TCK reference to PERSISTENCE_PROVIDER field to expect "jakarta.persistence.spi.PersistenceProvider" or remove PERSISTENCE_PROVIDER field and also update TCK signature tests.
This final String is deprecated and should be removed and is only here for TCK backward compatibility
protected static final Set<PersistenceProvider>
providers

Deprecated for removal since 3.2.
This instance variable is deprecated and should be removed and is only here for TCK backward compatibility

Constructor Summary

AccessConstructor and Description
public
Persistence()
Deprecated for removal since 3.2. This class is not intended to be extended nor instantiated, it is going to be marked final when this constructor becomes hidden.

Default constructor.

Method Summary

Modifier and TypeMethod and Description
public static EntityManagerFactory

Returns:

the factory that creates EntityManagers configured according to the specified persistence unit
createEntityManagerFactory
(String
the name of the persistence unit
persistenceUnitName
)

Create and return an EntityManagerFactory for the named persistence unit.

public static EntityManagerFactory

Returns:

the factory that creates EntityManagers configured according to the specified persistence unit
createEntityManagerFactory
(String
the name of the persistence unit
persistenceUnitName
,
Map<?, ?>
additional properties to use when creating the factory. These properties may include properties to control schema generation. The values of these properties override any values that may have been configured elsewhere.
properties
)

Create and return an EntityManagerFactory for the named persistence unit, using the given properties.

public static EntityManagerFactory

Returns:

the factory that creates EntityManagers configured according to the specified persistence unit
createEntityManagerFactory
(PersistenceConfiguration
configuration of the persistence unit
configuration
)

Create and return an EntityManagerFactory for the named persistence unit, using the given properties.

public static void
generateSchema(String
the name of the persistence unit
persistenceUnitName
,
Map<?, ?>
properties for schema generation; these may also contain provider-specific properties. The values of these properties override any values that may have been configured elsewhere.
map
)

Create database schemas and/or tables and/or create DDL scripts as determined by the supplied properties.

public static PersistenceUtil

Returns:

PersistenceUtil instance
getPersistenceUtil
()

Return the PersistenceUtil instance

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PERSISTENCE_PROVIDERback to summary
public static final String PERSISTENCE_PROVIDER

Deprecated

for removal since 3.2.

TODO: Either change TCK reference to PERSISTENCE_PROVIDER field to expect "jakarta.persistence.spi.PersistenceProvider" or remove PERSISTENCE_PROVIDER field and also update TCK signature tests.

This final String is deprecated and should be removed and is only here for TCK backward compatibility

Annotations
@Deprecated
since:3.2
forRemoval:true
Since
1.0
providersback to summary
protected static final Set<PersistenceProvider> providers

Deprecated

for removal since 3.2.

This instance variable is deprecated and should be removed and is only here for TCK backward compatibility

Annotations
@Deprecated
since:3.2
forRemoval:true
Since
1.0

Constructor Detail

Persistenceback to summary
public Persistence()

Deprecated

for removal since 3.2.

This class is not intended to be extended nor instantiated, it is going to be marked final when this constructor becomes hidden.

Default constructor.

Annotations
@Deprecated
since:3.2
forRemoval:true

Method Detail

createEntityManagerFactoryback to summary
public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName)

Create and return an EntityManagerFactory for the named persistence unit.

Parameters
persistenceUnitName:String

the name of the persistence unit

Returns:EntityManagerFactory

the factory that creates EntityManagers configured according to the specified persistence unit

createEntityManagerFactoryback to summary
public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map<?, ?> properties)

Create and return an EntityManagerFactory for the named persistence unit, using the given properties.

Parameters
persistenceUnitName:String

the name of the persistence unit

properties:Map<?, ?>

additional properties to use when creating the factory. These properties may include properties to control schema generation. The values of these properties override any values that may have been configured elsewhere.

Returns:EntityManagerFactory

the factory that creates EntityManagers configured according to the specified persistence unit

createEntityManagerFactoryback to summary
public static EntityManagerFactory createEntityManagerFactory(PersistenceConfiguration configuration)

Create and return an EntityManagerFactory for the named persistence unit, using the given properties.

Parameters
configuration:PersistenceConfiguration

configuration of the persistence unit

Returns:EntityManagerFactory

the factory that creates EntityManagers configured according to the specified persistence unit

Since
3.2
generateSchemaback to summary
public static void generateSchema(String persistenceUnitName, Map<?, ?> map)

Create database schemas and/or tables and/or create DDL scripts as determined by the supplied properties.

Called when schema generation is to occur as a separate phase from creation of the entity manager factory.

Parameters
persistenceUnitName:String

the name of the persistence unit

map:Map<?, ?>

properties for schema generation; these may also contain provider-specific properties. The values of these properties override any values that may have been configured elsewhere.

Exceptions
PersistenceException:
if insufficient or inconsistent configuration information is provided or if schema generation otherwise fails.
Since
2.1
getPersistenceUtilback to summary
public static PersistenceUtil getPersistenceUtil()

Return the PersistenceUtil instance

Returns:PersistenceUtil

PersistenceUtil instance

Since
2.0
jakarta.persistence back to summary

private Class Persistence.PersistenceUtilImpl

extends Object
implements PersistenceUtil
Class Inheritance
All Implemented Interfaces
jakarta.persistence.PersistenceUtil

Implementation of the PersistenceUtil interface
Since
2.0

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
isLoaded(Object
entity containing the attribute
entity
,
String
name of attribute whose load state is to be determined
attributeName
)

Implements jakarta.persistence.PersistenceUtil.isLoaded.

Determine the load state of a given persistent attribute.

public boolean
isLoaded(Object
whose load state is to be determined
entity
)

Implements jakarta.persistence.PersistenceUtil.isLoaded.

Determine the load state of an entity.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PersistenceUtilImplback to summary
private PersistenceUtilImpl()

Method Detail

isLoadedback to summary
public boolean isLoaded(Object entity, String attributeName)

Implements jakarta.persistence.PersistenceUtil.isLoaded.

Doc from jakarta.persistence.PersistenceUtil.isLoaded.

Determine the load state of a given persistent attribute.

Parameters
entity:Object

entity containing the attribute

attributeName:String

name of attribute whose load state is to be determined

Returns:boolean

false if entity's state has not been loaded or if the attribute state has not been loaded, else true

isLoadedback to summary
public boolean isLoaded(Object entity)

Implements jakarta.persistence.PersistenceUtil.isLoaded.

Doc from jakarta.persistence.PersistenceUtil.isLoaded.

Determine the load state of an entity. This method can be used to determine the load state of an entity passed as a reference. An entity is considered loaded if all attributes for which FetchType#EAGER has been specified have been loaded.

The isLoaded(Object, String) method should be used to determine the load state of an attribute. Not doing so might lead to unintended loading of state.

Parameters
entity:Object

whose load state is to be determined

Returns:boolean

false if the entity has not been loaded, else true