FlushMode.COMMIT/AUTO or remove 'readOnly'

项目之前运行好好的, 保存数据的时候突然报错:

javax.servlet.ServletException: 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.

 

到网上搜索后,发现: 在web.xml设置OpenSessionInViewFilter过滤器的话,会默认设置为FlushModeMANUAL ,

如果FlushMode是MANUAL或NEVEL,在操作过程中 hibernate会将事务设置为readonly,所以在增加、删除或修改操作过程中会出现以上错误, 如果在过滤加上这句就OK啦:

<init-param>   
  <param-name>flushMode</param-name>   
  <param-value>AUTO</param-value>   
</init-param>

你可能感兴趣的:(DAO,Hibernate,Web,xml,servlet)