`

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

ssh 
阅读更多
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
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics