The difference between a spring transaction and a configuration into a service and a DAO

Source: Internet
Author: User

Spring transactions Manage transactions for business logic, guaranteeing the atomicity of data on business logic.

Transactions are subdivided according to the nature of the project: transactions can be set to three levels (DAO layer, service layer, and Web tier).


First: Web-tier transactions, which are generally for systems with higher security requirements. such as e-commerce sites. Small size, the general system need not be so thin.
Second: Service layer transaction, which is a common transaction partition that sets the transaction on the business logic, as long as the business logic is faulted or the exception is rolled back on the transaction. Small size, generally recommended this way.
Third: Data persistence layer data service, that is, often said database transactions. This kind of transaction requires low security. is to give a simple addition and deletion of such operations to increase transaction operations. Large grain size

A transaction is configured for the service layer because a service layer method operation can be associated to multiple DAO operations. These DAO operations are performed at the service layer, and many DAO operations have failed all rollbacks, and the success is all committed.

The transaction is divided into business transaction and system transaction, business transaction is the consistency of operation on the business logic, the system transaction refers to the real database transaction naturally.

Spring configures transactions for what is managed, of course, for business logic transaction management, to ensure the atomicity of business logic data;
What is the DAO layer, the data access layer, should not contain business logic, which is different from the service layer;
The service layer is the business logic layer, and the management of the transaction is the guarantee on the service layer.

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.