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

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

猜你喜欢

转载自patronli.iteye.com/blog/2412785