Hibernate's lock

xiaoxiao2021-03-06  51

Hibernate's lock mode is: Ø LockMode.none: Locking mechanism. Ø LockMode.write: Hibernate is automatically obtained when INSERT and UPDATE records. Ø LOCKMODE.READ: Hibernate will be automatically obtained when reading the record. These three lock mechanisms are typically used inside Hibernate, such as Hibernate to ensure that the object does not be modified by the external modification during the UPDATE process, will automatically add Write locks in the Save method implementation. Ø LockMode.upgrade: Plock using the database's for Update clause. Ø LOCKMODE. UPGRADE_NOWAIT: Oracle's specific implementation, using Oracle's ForuPdate NOWAIT clause to lock. The above two lock mechanisms are more commonly used in the application layer, and the locking is generally implemented by the following methods: criteria.setession.lock Note that the lock is set before the start of the query (that is, Hiberate generates SQL) setting, The locking mechanism is really corrected through the database lock mechanism. Otherwise, the data has been loaded by SELECT SQL that does not contain the for Update clause, and the so-called database lock is not talked.

Hibernate has built an optimistic lock in its data access engine. If you don't have to consider the update operation of the external system for the database, use Hibernate's transparet optimistic lock implementation, will greatly improve our productivity. Hibernate can be specified in conjunction with the Version descriptor through the Optimistic-Lock property of the CLASS descriptor. Now, we add an optimistic lock mechanism for the Tuser in the previous example. Hibernate Developer's Guide Version 1.0september 2, 2004 SO MANY OPEN SOURCE PROJECTS. Why not open your document? 1. First add an Optimistic-Lock property to the Class descriptor of Tuser:

Name = "org.hibernate.sample.tuser"

Table = "t_user"

Dynamic-update = "True"

Dynamic-insert = "True"

Optimistic-Lock = "Version"

>

......

The Optimistic-Lock property has the following optional value: Ø None no optimistic lock Ø Version By version mechanism Implementing optimistic lock Ø DIRTY Implement the optimistic lock Ø All by checking all properties to implement optimistic locks through the Version implementation The optimistic lock mechanism is an optimistic lock implementation of Hibernate, and it is also hibernate, and the only lock mechanism is still unique in the case of data objects to be modified by session. Therefore, in general, we have chosen the Version mode as a Hibernate optimistic lock implementation mechanism.

转载请注明原文地址:https://www.9cbs.com/read-115304.html

New Post(0)