Write operations are not allowed in read-only mode (FlushMode.MANUAL)錯誤解決的一種方法

Write operations are not allowed in read-only mode (FlushMode.MANUAL)異常解決的一種方法
異常: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.

web.xml內容:
web

  <filter> <filter-name>hibernateFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping>spring



spring事件配置以下:
express

  <aop:config> <aop:pointcut id="txServices" expression="execution(* com.cnlive.dms.service..*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="txServices"/> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> </tx:attributes> </tx:advice>app



Service中是這樣的:
ide

  @Override public boolean createAdmin(Admin admin) { // TODO Auto-generated method stub Admin ad=adminDao.getAdminByUsername(admin.getUsername()); if(ad==null){ adminDao.insertAdmin(admin); return true; } return false; }url



在運行到createAdmin方法中的adminDao.insertAdmin(admin);時就報異常。

解決方法:
   將createAdmin方法配置到spring的事件中管理,添加了如下的一條配置

spa

  <tx:method name="create*" propagation="REQUIRED"/>hibernate



具體spring事件配置以下:
orm

  <aop:config> <aop:pointcut id="txServices" expression="execution(* com.cnlive.dms.service..*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="txServices"/> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="create*" propagation="REQUIRED"/> </tx:attributes> </tx:advice>xml



呵呵!問題就這樣簡單的解決了!不知道咱們碰到的問題是否同樣!

相關文章
相關標籤/搜索