Module io.ebean.api
Package io.ebean

Enum PersistenceContextScope

java.lang.Object
java.lang.Enum<PersistenceContextScope>
io.ebean.PersistenceContextScope
All Implemented Interfaces:
Serializable, Comparable<PersistenceContextScope>

public enum PersistenceContextScope extends Enum<PersistenceContextScope>
Defines the scope for PersistenceContext.

Ebean has traditionally used Transaction scope for the PersistenceContext. This is used to change the scope to use (by default) and explicitly set the scope to use for an individual query.

See Also:
  • Enum Constant Details

    • TRANSACTION

      public static final PersistenceContextScope TRANSACTION
      PersistenceContext is scoped to the transaction.

      If a transaction spans 2 or more queries that fetch the same bean in terms of same type and same Id value then they share the same bean instance.

      You may want to change to use QUERY scope when you want a query executing in a transaction to effectively ignore beans that have already been loaded (by other queries in the same transaction) and instead get a 'fresh copy' of the bean.

    • QUERY

      public static final PersistenceContextScope QUERY
      PersistenceContext is scoped to the query.

      This means that for this query running in an existing transaction then it will effectively ignore any beans that have already been queried/loaded by prior queries in the same transaction.

      You may use QUERY scope on a query that is executed in a transaction and you want to get a 'fresh copy' of the bean.

  • Method Details

    • values

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

      public static PersistenceContextScope valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified name
      NullPointerException - if the argument is null