HTTP Status 500 - 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. type Exception report message Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTOor remove 'readOnly' marker from transaction definition.
description The server encountered an internal error that prevented it from fulfilling this request. exception 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.
org.springframework.orm.hibernate5.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1126) org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:619) org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:616) org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:341)
.....
HTTP状态500-写入操作不允许在只读模式(FlushMode.MANUAL)中进行:将会话转换为FlushMode.COMMIT/AUTO,或从事务定义中删除“readOnly”标记。
错误原因:
代码中使用了@Transactional注解事务,因为你没有在applicationContext.xml中配置事务自动扫描,而使用了默认的只读模式,不能随代码运行自动刷新,
更正方法:
在applicationContext.xml文件中增加配置:
<!--配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 开启事务扫描,采用注解方式 --> <tx:annotation-driven transaction-manager="transactionManager" />
每天分享一个错误,快乐成长每一天!