1. 程式人生 > >關於hibernate中插入資料報read-only mode只讀模式錯誤

關於hibernate中插入資料報read-only mode只讀模式錯誤

專案中有時候會遇到插入資料到表中去報錯只讀模式

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

這種錯誤如果之前一直沒有,且未曾修改app-config-context.xml配置檔案,突然就出現了此類問題,一般都是由於自己開發中方法名取名和配置檔案中配置項衝突

例如方法名取名為  public void getsomething(){},若此方法中有事務提交(增、刪、改)表操作,將會報上述錯誤,因為配置項中已經配置get*為只讀模式,故只需將自己方法名中的get去掉或替換即可。

再重啟服務測試,此時發現問題得以解決!!