Hibernate automatic transaction pulling out of code is not canonical

Source: Internet
Author: User
Tags aop

Recently refactored project (Java beginner), service layer one get notification record error:

Org.springframework.dao.InvalidDataAccessResourceUsageException:could not execute statement; SQL [n/a]; Nested exception is org.hibernate.exception.SQLGrammarException:could not execute statement
....
Caused by:com.microsoft.sqlserver.jdbc.SQLServerException: The view or function ' V_web_notifylog ' is not updatable because the modification affects more than one base table.

Clearly is to get records, where to modify, troubleshooting logic, stored procedures ...

There is a property in the model to do the data modification operation (not specification 1)

      Public void setlaststate (String laststate) {          ifnull) {               this. LastState = " Unknown ";           Else {               this. laststate = laststate;          }     } 


At the end of the transaction (automated transactions configured through AOP) are automatically committed, and changes are made to the data back to the database, causing an error!

When you configure AOP, you explicitly define which services are read-only transactions, such as get*, find*, but this service is not named according to this (not canonical 2): Public resultdata prenotifystatus (int nid, int Action), instead of getnotifystatus problem resolution.

    <Tx:adviceID= "Txtadvice"Transaction-manager= "Txtmanager">        <tx:attributes>            <Tx:methodname= "find*"read-only= "true"Propagation= "REQUIRED" />            <Tx:methodname= "get*"read-only= "true"Propagation= "REQUIRED" />            <Tx:methodname= "login*"read-only= "true"Propagation= "REQUIRED" />            <Tx:methodname="*"Propagation= "REQUIRED" />        </tx:attributes>    </Tx:advice>

Summarize:

    1. Model do not do data modification, if you need to do simple data processing, you can consider doing in get*.
    2. Method name to standardize, get data such a read-only operation must use GET, find such verbs start, convenient global control.

Hibernate automatic transaction pulled out encoding not canonical

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.