You can use optimistic locking with version control. Optimistic version locking is enabled as soon as you add or property to map constant classes. The property mapping in XML should be placed immediately after the identifier property is displayed:
<class name="Item" table="ITEM">
<id .../>
<version name="version" access="field" column="OBJ_VERSION"/>
...
</class>
In this case, when the item is updated, SQL will:
update ITEM set INITIAL_PRICE='12.99', OBJ_VERSION=2
where ITEM_ID=123 and OBJ_VERSION=1
,
OBJ_VERSION 1, .
, JDBC
, , -
StaleObjectStateException.
, Hibernate
,
( ).
,
( , ).
, optimistic-lock
:
<class name="Item" table="ITEM" optimistic-lock="all">
<id .../>
...
</class>
SQL : update ITEM set ITEM_PRICE = '12.99 ' ITEM_ID = 123 ITEM_PRICE = '9.99' ITEM_DESCRIPTION = "" ... SELLER_ID = 45
, StaleObjectStateException. , , , .
"Java Persistent with Hibernate" CHRISTIAN BAUER GAVIN KING. ()
EDIT: . .