错误记录:[SSH] Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction

这个错我试了很多:

方法一:spring配置文件中加上

<!-- 配置事务通知
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes > -->
                <!-- 事务管理策略,查为只读 -->
                <!-- 事务隔离级别:mysql为可重复读,事务传播行为:默认值required -->isolation="REPEATABLE_READ" 
                <!-- <tx:method name="*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/> 
                <tx:method name="save*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/> 
                <tx:method name="update*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
                <tx:method name="delete*" isolation="REPEATABLE_READ" propagation="REQUIRED" />
                <tx:method name="find*" isolation="REPEATABLE_READ" propagation="REQUIRED" />
                <tx:method name="get*" isolation="REPEATABLE_READ" propagation="REQUIRED" />
                <tx:method name="*" isolation="REPEATABLE_READ" propagation="REQUIRED"/>
                <tx:method name="*" propagation="REQUIRED" read-only="false"/>
            </tx:attributes>
        </tx:advice>-->
        <!-- 配置事务AOP 
        <aop:config>
            <aop:pointcut expression="execution(* kim.service.impl.*.*(..))" id="pointcut1"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut1"/>
        </aop:config>-->

但是我的没有任何用处。无论我这么改这个部分

<tx:attributes > -->
                <!-- 事务管理策略,查为只读 -->
                <!-- 事务隔离级别:mysql为可重复读,事务传播行为:默认值required -->isolation="REPEATABLE_READ" 
                <tx:method name="*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/> 
                <tx:method name="save*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/> 
                <tx:method name="update*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
                <tx:method name="delete*" isolation="REPEATABLE_READ" propagation="REQUIRED" />
                <tx:method name="find*" isolation="REPEATABLE_READ" propagation="REQUIRED" />
                <tx:method name="get*" isolation="REPEATABLE_READ" propagation="REQUIRED" />
                <tx:method name="*" isolation="REPEATABLE_READ" propagation="REQUIRED"/>
                <tx:method name="*" propagation="REQUIRED" read-only="false"/>
            </tx:attributes>

然后尝试方法二:

先配置spring:

 <!-- 开启事务,记得在需要开启事务的类上 使用@Transaction-->
    <tx:annotation-driven transaction-manager="transactionManager"/>

在service层上面加上一个@Transactional,dao层中加一行getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);

 public void save(Customer customer) {
		getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);
        this.getHibernateTemplate().save(customer);
    }

然后就成功了,不过后面update又出问题

解决如下链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值