欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your

程序员文章站 2022-07-12 16:40:49
...
ssh整合后运行时常见的bug

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.
这是什么原因造成的呢?

这是因为ssh三个框架整合后,dao层主要用HibernateTemplate的方法对数据库进行操作导致的,这样必须得添加事务才能不出错。

具体的解决方法如下,我们可以在applicationContext.xml中开启一些事物
<!--配置事务管理器  -->  
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">  
<property name="sessionFactory" ref="sessionFactory"></property>  
</bean>  
<!-- 开启事务扫描,采用注解方式 -->  
<tx:annotation-driven transaction-manager="transactionManager"/>  

在我们的方法上加如下注解即可
@Transactional
相关标签: ssh