Enum Class FlushModeType

java.lang.Object
java.lang.Enum<FlushModeType>
jakarta.persistence.FlushModeType
All Implemented Interfaces:
EntityManager.CreationOption, EntityManager.Option, Serializable, Comparable<FlushModeType>, Constable

public enum FlushModeType extends Enum<FlushModeType> implements EntityManager.Option
Enumerates flush modes recognized by the EntityManager. The flush mode of a persistence context controls synchronization of modifications to managed entities with the database.

When a transaction is active and the persistence context is joined to the transaction, the persistence provider runtime is permitted to flush pending modifications to the database. The application can influence the timing of synchronization via the method EntityManager.flush(), by setting the FlushModeType, or by specifying a QueryFlushMode.

  • When the flush() method is called, the provider must synchronize every pending modification made to every entity currently associated with the persistence context.
  • The method EntityManager.setFlushMode(FlushModeType) can be used to control synchronization initiated automatically by the provider. Unless EXPLICIT is specified, all pending modifications are synchronized with the database when the transaction commits. When AUTO is specified, pending modifications might be automatically flushed to the database before execution of a query.
  • The effect of the FlushModeType of the entity manager may be overridden during execution of a given query by explicitly specifying a QueryFlushMode via the method Query.setQueryFlushMode(QueryFlushMode).

If there is no transaction active or if the persistence context has not been joined to the current transaction, the persistence provider must not flush modifications to the database.

An EntityAgent has no associated persistence context, and so flush modes have no effect on an entity agent, nor on Query objects created by an entity agent.

Since:
1.0
See Also:
  • Enum Constant Details

    • EXPLICIT

      public static final FlushModeType EXPLICIT
      Every flush is an explicit operation requested by the application program by calling EntityManager.flush(). The persistence context is never automatically flushed. Pending modifications to entities held in the persistence context might not be visible to the processing of queries and might never be made persistent.
      Since:
      4.0
    • COMMIT

      public static final FlushModeType COMMIT
      Pending modifications to entities associated with a persistence context joined to the current transaction are automatically flushed to the database when the transaction commits. The provider is permitted to flush at other times, but is not required to. Pending modifications to entities associated with the persistence context might not be visible to the processing of queries.
    • AUTO

      public static final FlushModeType AUTO
      Pending modifications to entities associated with a persistence context joined to the current transaction are automatically flushed to the database when the transaction commits. In addition, the persistence provider must ensure that every modification to the state of every entity associated with the persistence context which could possibly affect the result of a query is visible to the processing of the query. The persistence provider implementation might guarantee this by flushing pending modifications to the database before executing the query. The provider is permitted to flush at other times, but is not required to.

      This is the default flush mode for a newly created EntityManager.

  • Method Details

    • values

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