Enum Class PersistenceContextType

java.lang.Object
java.lang.Enum<PersistenceContextType>
jakarta.persistence.PersistenceContextType
All Implemented Interfaces:
Serializable, Comparable<PersistenceContextType>, Constable

public enum PersistenceContextType extends Enum<PersistenceContextType>
Specifies the lifecycle of a container-managed persistence context in a Jakarta EE container environment.
  • A transaction-scoped persistence context has a lifecycle bound to the current JTA transaction. The container is responsible for maintaining transactional affinity when a reference to an EntityManager is injected.
  • An extended persistence context has a lifecycle bound to an instance of a stateful session bean and may be inherited by other stateful session beans directly or indirectly instantiated by the first bean.

By default, a container-managed persistence context is transaction-scoped. The persistence context type for a container-managed persistence context is specified by PersistenceContext.type().

Since:
1.0
See Also:
  • Enum Constant Details

    • TRANSACTION

      public static final PersistenceContextType TRANSACTION
      A new persistence context begins when the container-managed entity manager is invoked in the scope of an active JTA transaction, and there is no current persistence context already associated with the transaction. The persistence context is created and associated with the transaction. This affinity of the persistence context with the JTA transaction is independent of the synchronization type of the persistence context and of whether the persistence context has been joined to the transaction.

      The persistence context propagates with the current JTA transaction to other injected transaction-scoped entity manager references with the same persistence unit and synchronization type.

      The persistence context ends when the associated transaction commits or rolls back, and all entities belonging to the persistence context become detached.

      If the entity manager is invoked outside the scope of a transaction, all entities loaded from the database immediately become detached at the end of the method call.

    • EXTENDED

      public static final PersistenceContextType EXTENDED
      The persistence context exists from the point at which the stateful session bean declaring a dependency on the persistence context is created. The container destroys the persistence context after the @Remove method of the stateful session bean completes or when the stateful session bean instance is otherwise destroyed.

      If a stateful session bean instantiates a stateful session bean (executing in the same EJB container instance) which also declares a dependency on an extended persistence context with the same unit and synchronization type, the extended persistence context of the first stateful session bean is inherited by the second stateful session bean. The container does not destroy an extended persistence context until every stateful session bean inheriting the persistence context has been removed or otherwise destroyed.

  • Method Details

    • values

      public static PersistenceContextType[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static PersistenceContextType valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null