Spring transaction management
A transaction is to treat a series of actions as a separate unit of work. these actions are either completed in full or all regardless of the four key properties of the transaction (ACID):-atomicity (atomicity): a transaction is an atomic operation consisting of a series of actions. the atomicity of the transaction ensures that the action is either completely completed or completely ineffective. -consistency: once all transaction actions are completed, the transaction is committed. data and resources are in a consistent state that satisfies business rules. -isolation: many transactions may process the same data at the same time. Therefore, each transaction should be isolated from other transactions to prevent data corruption. -durability: Once a transaction is completed, no matter what system error occurs, its results should not be affected. generally, transaction results are written to persistent storage. step 3: configure the Transaction Manager, configure the annotation driver, and add the @ Transactional annotation to the method.
<! -- Configure the Transaction Manager --> <! -- Jdbc Transaction Manager is cetcetransactionmanager Hibernate's Transaction Manager is HibernateTransactionManager --> <bean id = "transactionManager" class = "org. springframework. jdbc. datasource. dataSourceTransactionManager "> <property name =" dataSource "ref =" dataSource "> </property> </bean> <! -- Enable transaction annotation --> <tx: annotation-driven transaction-manager = "transactionManager"/>
Transaction propagation attributes when the transaction method is called by another transaction method, you must specify how the transaction should be propagated. for example, a method may continue to run in an existing transaction or start a new transaction and run it in its own transaction.