Top Description Fields Constructors Methods
org.hibernate

public final Class LockMode

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.HashMap, .Map

Instances represent a lock mode for a row of a relational database table. It is not intended that users spend much time worrying about locking since Hibernate usually obtains exactly the right lock level automatically. Some "advanced" users may wish to explicitly specify lock levels.
Author
Gavin King
See Also
Session#lock(Object, LockMode)

Field Summary

Modifier and TypeField and Description
public static final LockMode
FORCE

Similiar to UPGRADE except that, for versioned entities, it results in a forced version increment.

private static final Map<K, V>
private final int
private final String
public static final LockMode
NONE

No lock required.

public static final LockMode
OPTIMISTIC

Optimisticly assume that transaction will not experience contention for entities.

public static final LockMode
OPTIMISTIC_FORCE_INCREMENT

Optimisticly assume that transaction will not experience contention for entities.

public static final LockMode
PESSIMISTIC_FORCE_INCREMENT

Transaction will immediately increment the entity version.

public static final LockMode
PESSIMISTIC_READ

Implemented as PESSIMISTIC_WRITE.

public static final LockMode
PESSIMISTIC_WRITE

Transaction will obtain a database lock immediately.

public static final LockMode
READ

A shared lock.

public static final LockMode
UPGRADE

An upgrade lock.

public static final LockMode
UPGRADE_NOWAIT

Attempt to obtain an upgrade lock, using an Oracle-style select for update nowait.

public static final LockMode
WRITE

A WRITE lock is obtained when an object is updated or inserted.

Constructor Summary

AccessConstructor and Description
private
LockMode(int level, String name)

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this lock mode is more restrictive than given lock mode
greaterThan
(LockMode
LockMode to check
mode
)

Check if this lock mode is more restrictive than the given lock mode.

public boolean

Returns:

true if this lock mode is less restrictive than given lock mode
lessThan
(LockMode
LockMode to check
mode
)

Check if this lock mode is less restrictive than the given lock mode.

public static LockMode
parse(String name)

private Object
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

FORCEback to summary
public static final LockMode FORCE

Deprecated

instead use PESSIMISTIC_FORCE_INCREMENT

Similiar to UPGRADE except that, for versioned entities, it results in a forced version increment.

INSTANCESback to summary
private static final Map<K, V> INSTANCES
levelback to summary
private final int level
nameback to summary
private final String name
NONEback to summary
public static final LockMode NONE

No lock required. If an object is requested with this lock mode, a READ lock will be obtained if it is necessary to actually read the state from the database, rather than pull it from a cache.

This is the "default" lock mode.

OPTIMISTICback to summary
public static final LockMode OPTIMISTIC

Optimisticly assume that transaction will not experience contention for entities. The entity version will be verified near the transaction end.

OPTIMISTIC_FORCE_INCREMENTback to summary
public static final LockMode OPTIMISTIC_FORCE_INCREMENT

Optimisticly assume that transaction will not experience contention for entities. The entity version will be verified and incremented near the transaction end.

PESSIMISTIC_FORCE_INCREMENTback to summary
public static final LockMode PESSIMISTIC_FORCE_INCREMENT

Transaction will immediately increment the entity version.

PESSIMISTIC_READback to summary
public static final LockMode PESSIMISTIC_READ

Implemented as PESSIMISTIC_WRITE. TODO: introduce separate support for PESSIMISTIC_READ

PESSIMISTIC_WRITEback to summary
public static final LockMode PESSIMISTIC_WRITE

Transaction will obtain a database lock immediately. TODO: add PESSIMISTIC_WRITE_NOWAIT

READback to summary
public static final LockMode READ

A shared lock. Objects in this lock mode were read from the database in the current transaction, rather than being pulled from a cache.

UPGRADEback to summary
public static final LockMode UPGRADE

Deprecated

instead use PESSIMISTIC_WRITE

An upgrade lock. Objects loaded in this lock mode are materialized using an SQL select ... for update.

UPGRADE_NOWAITback to summary
public static final LockMode UPGRADE_NOWAIT

Attempt to obtain an upgrade lock, using an Oracle-style select for update nowait. The semantics of this lock mode, once obtained, are the same as UPGRADE.

WRITEback to summary
public static final LockMode WRITE

A WRITE lock is obtained when an object is updated or inserted. This lock mode is for internal use only and is not a valid mode for load() or lock() (both of which throw exceptions if WRITE is specified).

Constructor Detail

LockModeback to summary
private LockMode(int level, String name)

Method Detail

greaterThanback to summary
public boolean greaterThan(LockMode mode)

Check if this lock mode is more restrictive than the given lock mode.

Parameters
mode:LockMode

LockMode to check

Returns:boolean

true if this lock mode is more restrictive than given lock mode

lessThanback to summary
public boolean lessThan(LockMode mode)

Check if this lock mode is less restrictive than the given lock mode.

Parameters
mode:LockMode

LockMode to check

Returns:boolean

true if this lock mode is less restrictive than given lock mode

parseback to summary
public static LockMode parse(String name)
readResolveback to summary
private Object readResolve()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.