The things management----HelloWorld in spring

Source: Internet
Author: User

Understand a few concepts before you learn spring's things management
1 What is a thing: a transaction is a series of actions that are treated as a separate unit of work. These actions are either complete or not working.
Examples: For example, bank transfer, a account transfer (200) to the B account, the action involved is a account balance reduction 200,b account balance increased by 200, the two actions as a work unit, or two actions to complete together, or two actions are not

2 What is the function of the thing: there are four characteristics, namely: atomicity (that is, multiple actions make up an atomic operation, either done together or not together)
Consistency (that is, when things are done, data and resources remain consistent)
Isolation (many transactions can handle the same data at the same time, so everything should be isolated from other transactions to prevent data corruption)
Persistence (Once a transaction is complete, its results should not be affected, no matter what system error occurs.) Typically, the result of a transaction is written to persistent memory)

Things to manage in spring use the steps:

* Steps to work with transactions:
* 1 Configure the transaction manager first (each data source spring has a corresponding transaction manager) (because the data source manager is managing the data source, you want to add the data source properties)

<id= "TransactionManager"  class= " Org.springframework.jdbc.datasource.DataSourceTransactionManager ">        <  name = "DataSource" ref = "DataSource" ></  Property >    </ Bean >

* 2 Enable transaction annotations

<!---    <Transaction-manager = " TransactionManager "/>

* 3 Use @transactional in front of the method that needs to be managed, which puts the method into the transaction manager for Management

@Transactional    @Override    publicvoid  Purchase (string Username, String ISBN) {                 // 1. The unit price of the book is          bookshopdao.findbookpricebyisbn (ISBN);                 // 2. Updated inventory         Bookshopdao.updatebookstock (ISBN);                 // 3. Update the user balance         bookshopdao.updateuseraccount (username, price);    }


* 4 Why can't I use it in the test class????

The things management----HelloWorld in spring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.