Enum Class SynchronizationType

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

public enum SynchronizationType extends Enum<SynchronizationType>
Specifies whether the persistence context associated with an EntityManager is always automatically synchronized with the current transaction.
  • SYNCHRONIZED indicates that the persistence context is automatically joined to the current transaction, and that modifications are always automatically synchronized with the database according to the current flush mode.
  • UNSYNCHRONIZED indicates that the persistence context is not automatically joined to the current transaction, and that its modifications are not synchronized with the database until it is explicitly joined to the current transaction by calling EntityManager.joinTransaction().

By default, a container-managed persistence context is of type SYNCHRONIZED and is automatically joined to the current transaction. A container-managed persistence context of type UNSYNCHRONIZED is not enlisted in the current transaction until joinTransaction() is called. The synchronization type for a container-managed persistence context is specified by PersistenceContext.synchronization().

By default, an application-managed persistence context associated with a JTA entity manager and created within the scope of an active JTA transaction is automatically joined to that transaction. An application-managed JTA persistence context created outside the scope of an active JTA transaction, or any application-managed persistence context created with type UNSYNCHRONIZED, is not enlisted with a transaction until joinTransaction() is called. The synchronization type for an application-managed JTA persistence context is specified via EntityManagerFactory.createEntityManager(SynchronizationType).

An application-managed persistence context associated with a resource-local entity manager is always automatically joined to any resource-local transaction begun for that entity manager.

Since:
2.1
See Also:
  • Enum Constant Details

    • SYNCHRONIZED

      public static final SynchronizationType SYNCHRONIZED
      The persistence context is automatically joined to the current transaction, and modifications are automatically synchronized with the database according to the current flush mode.
    • UNSYNCHRONIZED

      public static final SynchronizationType UNSYNCHRONIZED
      The persistence context must be explicitly joined to the current transaction by calling EntityManager.joinTransaction(). When the persistence context is not joined to a transaction, modifications cannot be synchronized with the database, regardless of the current flush mode. The persistence provider must not flush pending modifications to the database until the persistence context is joined to a transaction.
  • Method Details

    • values

      public static SynchronizationType[] 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 SynchronizationType 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