最近重構的項目(java初學中),Service層一個獲取通知記錄報錯:
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: 視圖或函數 'v_web_NotifyLog' 不可更新,因為修改會影響多個基表。
明明是獲取記錄,哪來的修改,排查邏輯,存儲過程...模型里面有一屬性做了數據修改操作(不規范1)
public void setLastState(String lastState) { if (lastState == null) { this.lastState = "未知"; } else { this.lastState = lastState; } }
在事務結束時(通過AOP配置的自動事務)就會自動提交,將更改回寫數據到數據庫,就引發了錯誤!在配置AOP時明確制定了哪些Service是只讀事務,比如get*、find*,但是這個Service就沒有按照這種命名(不規范2):public ResultData preNotifyStatus(int nid, int action) , 改為getNotifyStatus 問題解決。
<tx:advice id="txtAdvice" transaction-manager="txtManager"> <tx:attributes> <tx:method name="find*" read-only="true" propagation="REQUIRED" /> <tx:method name="get*" read-only="true" propagation="REQUIRED" /> <tx:method name="login*" read-only="true" propagation="REQUIRED" /> <tx:method name="*" propagation="REQUIRED" /> </tx:attributes> </tx:advice>
總結:
新聞熱點
疑難解答