最近重構(gòu)的項(xiàng)目(java初學(xué)中),Service層一個(gè)獲取通知記錄報(bào)錯(cuò):
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: 視圖或函數(shù) 'v_web_NotifyLog' 不可更新,因?yàn)樾薷臅?huì)影響多個(gè)基表。
明明是獲取記錄,哪來的修改,排查邏輯,存儲(chǔ)過程...模型里面有一屬性做了數(shù)據(jù)修改操作(不規(guī)范1)
public void setLastState(String lastState) { if (lastState == null) { this.lastState = "未知"; } else { this.lastState = lastState; } }
在事務(wù)結(jié)束時(shí)(通過AOP配置的自動(dòng)事務(wù))就會(huì)自動(dòng)提交,將更改回寫數(shù)據(jù)到數(shù)據(jù)庫,就引發(fā)了錯(cuò)誤!在配置AOP時(shí)明確制定了哪些Service是只讀事務(wù),比如get*、find*,但是這個(gè)Service就沒有按照這種命名(不規(guī)范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>
總結(jié):
新聞熱點(diǎn)
疑難解答
圖片精選