菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
405
0

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.

原创
05/13 14:22
阅读数 97133

只读模式下(FlushMode.NEVER/MANUAL)写操作不被允许:把你的Session改成FlushMode.COMMIT/AUTO或者清除事务定义中的readOnly标记。

在applicationContext.xml中添加如下配置:

 1     <!--事务管理器-->
 2     <bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
 3         <property name="sessionFactory" ref="sessionFactory"></property>
 4     </bean>
 5 
 6     <aop:config>
 7         <!-- execution(public * *.*.*..*.*(..)) 为自己项目中操作数据库中的方法 -->
 8         <aop:pointcut id="pointcut" expression="execution(* com.gyf.bos.dao..*.*(..))" />
 9         <aop:advisor pointcut-ref="pointcut" advice-ref="txAdvice" />
10     </aop:config>
11 
12     <!-- 配置事务增强 -->
13     <tx:advice id="txAdvice" transaction-manager="txManager">
14         <tx:attributes>
15             <!-- 配置需要进行事务管理的方法,和事务传播行为 -->
16             <tx:method name="save*" propagation="REQUIRED" read-only="false"/>
17             <tx:method name="update*" propagation="REQUIRED" read-only="false"/>
18             <tx:method name="delete*" propagation="REQUIRED" read-only="false"/>
19         </tx:attributes>
20     </tx:advice>

说明:execution(* com.gyf.bos.dao..*.*(..))

    该步骤还没有添加service,后期会整合,在这里仅提供配置参考

发表评论

0/200
405 点赞
0 评论
收藏