Hibernate Transactions and Concurrency Control

https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/transactions.html

 

 

http://blog.csdn.net/qjyong/article/details/1874599

 

 Hibernate Transactions and Concurrency Control

                                   
1.     Business introduction:
1.1.        Definition of transaction:
A transaction is a set of data operations performed as a single logical unit of work that must either all succeed or all fail to ensure data consistency and integrity.
1.2.        Transactions have ACID properties:
Atomic : A transaction consists of one or more actions bound together as if it were a single unit of work. Atomicity ensures that all operations in a transaction either occur or none of them occur.
Consistent : Once a transaction ends (whether successful or not), the state of the system is consistent with its business rules. That is, the data should not be corrupted.
oIsolated  ( Isolated ): A transaction should allow multiple users to operate on the same data, and the operations of one user will not be confused with the operations of other users.
Durable (Durable): Once the transaction is completed, the results of the transaction should be durable.
The ACID properties of transactions are implemented by relational database management systems (RDBMS).
o Database management systems use logs to ensure transaction atomicity, consistency, and durability. The log records the updates made by the transaction to the database. If an error occurs during the execution of a transaction, the update that the transaction has made to the database can be undone according to the log, so that the database returns to the initial state before executing the transaction.
o The database management system uses a locking mechanism to achieve transaction isolation. When multiple transactions update the same data in the database at the same time, only the transaction holding the lock is allowed to update the data, and other transactions must wait until the previous transaction releases the lock before other transactions have the opportunity to update the data.
2.     Database transaction statement:
As long as the client program of the database system declares a transaction to the database system, the database system will automatically guarantee the ACID characteristics of the transaction. In the JDBC API, the java.sql.Connection class represents a database connection. It provides the following methods to control transactions:
1.           setAutoCommit(Boolean autoCommit): Set whether to automatically commit the transaction.
2.           commit(): Commit the transaction.
3.           rollback(): undo the transaction.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326211686&siteId=291194637