zoukankan      html  css  js  c++  java
  • org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

    源代码

    public Authentication deleteById(String id) {
            Authentication entity = super.get(id);
            if (entity != null) {
                getSession().delete(entity);
            }
            return entity;
        }

    场景:平台的前台和后台为不同的用户登录,前台刷新页面的过程中,后台的页面刚好退出登录,拦截器在前台获取到了后台的用户信息,但此时后台用户信息在退出时已被删除,后台用户实体处于托管态。

    异常分析:实体是托管态的时候,根据实体删除会报错。

    修改后的代码

    public Authentication deleteById(String id) {
            Authentication entity = super.get(id);
            /*此处改为HQL语句删除,原因是直接删除对象如果是托管态的话会报错*/
            if (entity != null) {
                String hql = "delete Authentication bean where bean.id=:id";
                getSession().createQuery(hql).setParameter("id", id)
                        .executeUpdate();
            }
            return entity;
        }
  • 相关阅读:
    Linux下对拍(A+B问题)
    洛谷 P1043 数字游戏 区间DP
    6.22 集训--DP复习一
    洛谷 P1220 关路灯 区间DP
    A*算法求K短路模板 POJ 2449
    点分治模板 POJ 1741
    HDU
    棋子游戏 51Nod
    数论习题总结
    CodeForces
  • 原文地址:https://www.cnblogs.com/againn/p/7792233.html
Copyright © 2011-2022 走看看