Springmvc+hibernate Schema Save method Transaction not committed

Source: Internet
Author: User

Today to outsource the job encountered a problem, called me to study together, finally resolved, let me on the spring management and deepened the impression.

Let's start with the project: The project is spring and hibernate integrated Java EE project, MVC architecture.

Outsourcing in the service layer a get Start method to write some business logic, called the DAO layer of the Save and get method, but found that the get data normal display, the data table that save is not stored in the data table, The SQL generated by hibernate only found the Get statement, did not find the Save statement, and did not report any errors. Very strange phenomenon, not afraid of error, it is afraid that it does not error ~

Then checked the code again, no suspicion was found. Break point trace found that this thing of save can get in the program, prove that hibernate cache has the value of save, it may be hibernate did not commit save, but write in the same method of get normal commit. A configuration problem was thought of because the transaction was configured at the service layer, while the other tiers did not.

So, the spring configuration file is found:

            <name= "get*"  propagation= "REQUIRED"  read-only= "True"/>            <name= "save*"  Propagation  = "REQUIRED"/>

Yusimeng found that the transaction with the service method starting with Get has a read-only property configured. The read-only of the service method starting with Save is the default value of FALSE.

The reason was found: Because the service method starts with get, only the Read permission does not have permission to write, and the Save action cannot be committed.

Solution:

1, the simplest. The method name does not start with get, starting with other strings configured with the required isolation level prefix.

2, comparative norms. DAO layer of the basic addition and deletion of the action are implemented in the service layer (call DAO), and configure the appropriate permissions for the transaction, to provide a unified transaction with a separate and delete service method, and then both within the service class or outside the class call these basic additions and deletions to implement business logic.

I recommend program 2.

Springmvc+hibernate Schema Save method Transaction not committed

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.