2010年12月1日 星期三

Transaction manager教學

原因:使用OpenSessionInViewFilter時,session被設定為readOnly。

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

解決方式:
1. 增加TransactionManager.xml,如下xml。
其中在*ServiceImpl.java中的method名稱開頭為delete, save及merge,才可被與許存取DB。
2. 在web.xml加上TransactionManager.xml路徑