Package org.hibernate

Enum Class Locking.Scope

java.lang.Object
java.lang.Enum<Locking.Scope>
org.hibernate.Locking.Scope
All Implemented Interfaces:
FindOption, LockOption, RefreshOption, Serializable, Comparable<Locking.Scope>, Constable
Enclosing interface:
Locking

public static enum Locking.Scope extends Enum<Locking.Scope> implements FindOption, LockOption, RefreshOption
When pessimistic locking is requested, this enum defines what exactly will be locked.
See Also:
API Note:
Same intention as the JPA PessimisticLockScope, but offering the additional INCLUDE_FETCHES behavior.
  • Enum Constant Details

    • ROOT_ONLY

      public static final Locking.Scope ROOT_ONLY
      Lock the database row(s) that correspond to the non-collection-valued persistent state of that instance. If a joined inheritance strategy is used, or if the entity is otherwise mapped to a secondary table, this entails locking the row(s) for the entity instance in the additional table(s).
      See Also:
    • INCLUDE_COLLECTIONS

      public static final Locking.Scope INCLUDE_COLLECTIONS
      In addition to the locking behavior specified for ROOT_ONLY, rows for collection tables (ElementCollection, OneToMany and ManyToMany) will also be locked.

      Hibernate will only lock these collection rows when they are joined. The alternatives would be to either:

      • Add joins for the collection tables, which is problematic because
        • if inner joins are added, the results will be unexpectedly affected
        • if outer joins are added, many databases do not allow locking outer joins
      • Perform follow-on locking which can lead to deadlocks.
      See Also:
      API Note:
      Locking only joined rows is arguably not fully compliant with the specification. However, we believe it is the best implementation.
    • INCLUDE_FETCHES

      public static final Locking.Scope INCLUDE_FETCHES
      All tables with fetched rows will be locked.
      API Note:
      This is Hibernate's legacy behavior, and has no corresponding JPA scope.
  • Method Details

    • values

      public static Locking.Scope[] 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 Locking.Scope 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
    • getCorrespondingJpaScope

      public PessimisticLockScope getCorrespondingJpaScope()
      The JPA PessimisticLockScope which corresponds to this Scope.
      Returns:
      The corresponding PessimisticLockScope, or null.
    • fromJpaScope

      public static Locking.Scope fromJpaScope(PessimisticLockScope scope)
    • interpret

      public static Locking.Scope interpret(String name)