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:
- Model do not do data modification, if you need to do simple data processing, you can consider doing in get*.
- 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